Chapter 14. Event Triggers and Animation

The property triggers described in the previous chapter let you detect specific property values and change some property's value in response. For example, a Button might detect when IsMouseOver is True and change its scale to make the Button grow when the mouse is over it.

Event triggers and animation add a new dimension to this type of responsiveness. An event trigger lets you detect when an event occurs. Animation lets you change property values in a series of smoothly varying steps. Together, for example, you can make a Button detect the MouseOver event and use animation to enlarge the Button, providing graphical feedback similar to the experience provided by the previous property event.

So, what's the difference? First, WPF controls provide many events that are not provided by watching property values. For example, while a Button has an IsMouseOver property to tell you when the mouse is over it, there are no properties that directly correspond to the events MouseEnter, MouseLeave, MouseDown, MouseUp, MouseMove, and Click.

Second, a setter used by property triggers immediately changes a property's value. In contrast, an animation makes a property value gradually change over time. The end result is similar, but the user can see the change in the value as it happens. For example, instead of making a button suddenly pop to a new size, an animation makes it gradually grow. Often the difference isn't critical — the button ends up with the same ...

Get WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4 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.