Advanced programming


You use triggers to program the dynamic behavior of a graphic element.

For each graphical property that you want to influence with triggers, you should first set the initial value in the "Style.Setters Collection" per setter (see previous chapter).

To define triggers, open the trigger window using the "Edit Style Trigger" context command:

 


With the trigger window you can create either

The simplest form are property triggers. Property triggers are needed when one dependency property is to change when another has changed. Usually these are so-called "Is properties" that change their Boolean value when a mouse or keyboard event is triggered.

 

 

  1. To add a simple property trigger, click the Property button. To add a multiple property trigger, click the "Multi" button.
  2. Select the event property in the "Triggerdata" tab and define the value to which you want to react.
  3. Switch to the "Setter" tab and define which graphical property should change. 

Then close the trigger window and switch to the XAML editor. The following code was generated for our rectangle example:

 

Translated this means: "If the mouse pointer is over the rectangle, change the fill color to yellow."

In practice, property triggers are not needed that often. Rather, data triggers are used, which are discussed in more detail in the following subchapter.