Element Property Binding Improvements in Blend 4 Beta and Visual Studio 2010 RC

Posted by on Comments (0)

Element to element binding was new with Silverlight 3.0.

To know more about it, I invite you to read this post from Jeff Prosise.

Some improvements are made in Blend 4 Beta and Visual Studio 2010 RC to improve your everyday work on this point.

The old way (Blend 3.0/Visual Studio 2008)

Suppose that you want to bind the value of a Slider to a TextBlock text :

In Blend 3.0, you must select the TextBlock, go into the common properties, select the Text property and the Data Binding in the contextual menu :

Once this is made, you must select the Element Property, browse the three to find the element and the property to bind to.

In Visual Studio 2008, there was nothing to help you to generate this simple XAML piece:

<TextBlock Height="32" Margin="8,0,12,8" VerticalAlignment="Bottom" Text="{Binding Value, ElementName=slider, Mode=OneWay}" TextWrapping="Wrap"/>

The new way (Blend 4.0 beta/VS 2010 RC)

In Blend 4.0, you still have the same option. But you also have a more friendly option with the new "Element Property Binding" option.

Choosing that item, you only have to select the element you want to bind to with your mouse :

A new dialog then opens to ask you which property you want to bind to :

In Visual Studio 2010 RC, you also now have now the option to work with the properties window to do the same thing.

Go to the Text property in the Properties window. Click on the small Value Source icon :

Select "Apply Data Binding"

In the dialog that appears, select an ElementName source, choose the slider :

Then in the Path, choose the property you want to bind to :