Element to element binding
Data binding is classically done between a user interface element and a data object. Sometimes, however, it's useful to bind one element's property to another's property. This can reduce (or even eliminate) the need for handling conventional events. Let's see how to make this work. This will also serve as a good start for doing bindings of any kind.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create a Slider
that affects the font size of a TextBlock
without using any code.
Create a new WPF application named
CH06.ElementToElementBindings
.Open
MainWindow.xaml
. Add the following markup to the existingGrid
:<Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBlock Text="This is a sizing text" TextAlignment="Center" VerticalAlignment="Center"/> <Slider x:Name="_slider" Grid.Row="1" Minimum="10...