Binding to multiple properties
So far we've seen data binding occur for a target property base on a single source property. Sometimes, however, a target property depends on changes of more than one source property. This is supported in WPF through multi binding. Let's see how it's done.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create a simple color selector using a multi-binding.
Create a new WPF application named
CH06.MultiBindings
.Open
MainWindow.xaml
. Add the following to the existingGrid
:<Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Rectangle Stroke="Black" StrokeThickness="1" Margin="4" > </Rectangle> <Slider Minimum="0" Maximum="255" Margin="4" x:Name="_red" Grid.Row="1" /> <Slider Minimum="0" Maximum="255" Margin="4" x:Name="_green" Grid.Row="2" />...