Using data triggers

Property triggers work with dependency properties only, but what about regular properties? This is where data triggers come in. They are able to inspect any property, but their usefulness lies within data templates that naturally bind to data objects (which utilize non-dependency properties). Let's see how to set that up.

Getting ready

Make sure Visual Studio is up and running.

How to do it...

We'll create a simple application to show books with a DataTemplate that is customized with data triggers to show some books a bit differently:

  1. Create a new WPF application named CH08.DataTriggerDemo.
  2. Add a new class to the project named Book and implement it as follows:
    class Book { public string BookName { get; set; } public string AuthorName ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.