-
Book Overview & Buying
-
Table Of Contents
Windows Presentation Foundation 4.5 Cookbook
By :
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.
Make sure Visual Studio is up and running.
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:
Create a new WPF application named CH08.DataTriggerDemo.
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; set; }
public bool IsFree { get; set; }
}Open MainWindow.xaml. Add a ListBox to the existing Grid and set a few properties:
<ListBox HorizontalContentAlignment="Stretch"
ItemsSource="{Binding}">We'll create a DataTemplate...