O'Reilly logo

WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4 by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required