WiseOwl Training - Established 1992 Wise Owl Training

Established May 1992
30 years in business
Wise Owl Training
30 years in business
See 482 reviews for our classroom and online training
Why you should develop systems in WPF, not WinForms
Part nine of a eleven-part series of blogs

Posted by Andy Brown on 25 September 2012

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

8 - Triggers

There are two main types of trigger in WPF: property triggers and event triggers.

Property Triggers

In Windows Forms, if you want a text box to be shaded when you mouse over it, you have to code this. 

Coloured textbox in form

When you move the mouse over this textbox, it should go pink.


In WPF you can just write a property trigger in XAML:

A property trigger in WPF

The trigger which makes this work: when the IsMouseOver property of the textbox becomes true, change the background colour to Pink.


Event Triggers

Event triggers have two main extra features: they allow controls to interact with each other, and they produce animated effects.  So you could (for example) get a form to gradually change background from white to grey when you hover over an OK button - but to do that we'll need to have a look at storyboards and animation, the next part of this blog series.


This blog has 0 threads Add post