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.

  1. Create a new WPF application named CH06.MultiBindings.
  2. Open MainWindow.xaml. Add the following to the existing Grid:
    <Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Rectangle Stroke="Black" StrokeThickness="1" Margin="4" > </Rectangle> ...

Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.