Welcome to WindowsClient.net | My Blog | Sign in | Join

Windows Client Videos

Interactivity Through Triggers in WPF Control Templates

Control templates in WPF give us the capability to alter the visual appearance of any control.  When we override the default visual of a control, we often lose many of the interactive behaviors of the control.  For example, we typically lose visual indicators of the mouse interaction with the control.  The video demonstrates using triggers in control templates to regain that visual interactivity.

Author: Todd Miranda

Comments

modestyZ said:

Since this control template triggers only have setters, would it be better to move all these triggers to Style triggers? Because template is more about composite visual trees while style is more about setters (to change properties).

Agree? Don't agree? Doesn't matter?

# February 1, 2008 12:21 AM

tmiranda said:

Sorry for the delay. Good Question!

At this point there really aren't clear guidelines on when to use template triggers vs. style triggers. There are some objects that support styles but not templates and some objects that support templates but not styles.  The easiest examples of this are panels which don't support templates and things like data objects that don't support styles. Furthermore, a style is only knowledgeable about the logical element it is applied to and can't access any of the internal visual structure defined by a more complex visual tree.  A control template knows all about the visual makeup of the element and thus has access to affect more of the element's visual components.

So bottom line is that when to use styles vs templates depends on how you are using it and what level of access you need the elements visual tree.

Hopefully this helps a little.

# March 1, 2008 12:17 PM