Element-to-element data binding
In the last few recipes, we learned how to do object-to-element data binding. Though this is commonly used, you will need element-to-element data binding within the same XAML page to reduce the extra lines of codes in the code-behind file. In this recipe, we will learn how to do this.
Getting ready
First, launch your Visual Studio IDE and create a new WPF application project. Give it the name CH04.ElementToElementBindingDemo
.
How to do it...
Now perform the following steps to design the UI with a TextBlock
and a Slider
control. Then we will bind the value of the slider control with the FontSize
property of the TextBlock
:
- Open the
MainWindow.xaml
page and replace the defaultGrid
panel with the following XAML markup:
<Grid> <TextBlock FontSize="{Binding Value, ElementName=fontSizeSlider}" Margin="4" HorizontalAlignment="Center" VerticalAlignment="Center"> <Run Text="Font Size:"/>...