Creating a property trigger

So far we've used styles that have a collection of setters. A Style also has a Triggers collection property that provides a declarative way to make some property changes without a need for actual code. As such triggers are part of a style, they are naturally applied to more than one element. There are three types of triggers supported by WPF, and in this recipe we'll examine the simplest one - the property trigger.

Getting ready

Open the CH08.StyledCalculator project.

How to do it...

We'll add an effect when clicking a button in the calculator project using a property trigger:

  1. We want to add a trigger to one of the styles we created in an earlier recipe. Open MainWindow.xaml and look for the style with the key numericStyle ...

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.