Triggers

One of the themes in WPF is extending what you can do declaratively. Whether you're using styles, resources, or data binding, you'll find that you can do quite a bit without resorting to code.

Triggers are another example of this trend. Using triggers, you can automate simple style changes that would ordinarily require boilerplate event-handling logic. For example, you can react when a property is changed and adjust a style automatically.

Triggers are linked to styles through the Style.Triggers collection. Every style can have an unlimited number of triggers, and each trigger is an instance of a class that derives from System.Windows.TriggerBase. WPF gives you the choices listed in Table 12-2.

You can apply triggers directly to elements, ...

Get Pro WPF in C# 2008: Windows Presentation Foundation with .NET 3.5, Second Edition 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.