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.

  1. Create a new WPF application named CH06.ElementToElementBindings.
  2. Open MainWindow.xaml. Add the following markup to the existing Grid:
    <Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> <RowDefinition ...

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.