Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

Bind a Property to an Action with a WPF Measurement Studio Control

 

Overview
This is a simple example that binds a button click from one button to the color property of another button using the WPF controls in Measurement Studio.

 
Description
This example is simple example that demonstrates how to bind an action, in this case a mouse click, to change a property on another contorl. In this example we are changing  the case the color of another button. There are a few key pieces of code required to make this successful. One is in the XAML itself:

<Grid>

        <ni:BooleanButton Content="Button 1"  HorizontalAlignment="Left" Height="23" \

          VerticalAlignment="Top"  Width="75" Background="{Binding MyBrushProperty}"  Margin="159,58,0,0"/>

        <Button Content="Click to turn  Button 1 Red" HorizontalAlignment="Left" \

          VerticalAlignment="Top"  Width="190" Margin="100,137,0,0" Click="Button_Click"/>

</Grid>

In this snippet, we can see that we are binding the background color of the BooleanButton to MyBrushProperty. This leads us to the second piece of code that is really nessicary in order to complete this functionality:

public DependencyProperty MyBrushProperty = DependencyProperty.Register(

            "MyBrushProperty", typeof(SolidColorBrush), typeof(Window)

            );

which is defined in our mainwindow class. This declares our databinding target as a DependencyProperty which is a component that is exposed in the CLR. Essentially it allows us to make changes to properties based on another set of inputs. This code allows us to expose the MyBrushProperty propert as a Depency Property so that we can perform bind data to it.


Requirements

  • Visual Studio 2012
  • Measurement Studio Enterprise 2013 (or compatible)


Steps to Implement or Execute Code

  1. Download and Unzip the file.
  2. Fix an Dependcy issues that you may find run into
  3. Run the Source code.
  4. Click "Click to turn Button 1 Red" in order to change the color of button 1
  5. Close the Application

 

Additional Information or References
Example what the the application looks like after click the button.

FP.png 

 

Related Links

MSDN: Dependency Properties Overview

MSDN: Dependency Property Class

MSDN Walkthrough: Getting Started with WPF

NI Measurement Studio

 

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

 

Kurt P
Automated Test Software R&D