Tuesday, April 8, 2008

Element to Element Data Binding

<Slider Name="sliderFontSize" Minimum="1" Maximum="40" Value="10" TickFrequency="1" TickPlacement="TopLeft" />
<TextBlock Name="lblSampleText" Text="Simple Text" FontSize="{Binding Source=sliderFontSize, Path=Value}" />
The TextBlock's FontSize will change to the slider control's value. This binding in the xaml is saying, "Create a binding to the sliderFontSize.Value property."
Here's how you would create the equivalent binding in C#:
Binding binding = new Binding();
binding.Source = sliderFontSize;
binding.Path = new PropertyPath("Value");
lblSampleText.SetBinding(TextBlock.FontSizeProperty, binding);
More Info: Data Binding