wpfTriggers


Introduction

Discussion on the various types of Triggers available in WPF, including Trigger, DataTrigger, MultiTrigger, MultiDataTrigger, and EventTrigger.

Triggers allow any class that derives from FrameworkElement or FrameworkContentElement to set or change their properties based on certain conditions defined in the trigger. Basically, if an element can be styled, it can be triggered as well.

Remarks

  • All triggers, except for EventTrigger must be defined within a <Style> element. An EventTrigger may be defined in either a <Style> element, or a control's Triggers property.
  • <Trigger> elements may contain any number of <Setter> elements. These elements are responsible for setting properties on the containing element when the <Trigger> element's condition is met.
  • If a property is defined in the root element markup, the property change defined in the <Setter> element will not take effect, even if the trigger condition has been met. Consider the markup <TextBlock Text="Sample">. The Text property of the proceeding code will never change based on a trigger because root property definitions take precidence over properties defined in styles.
  • Like bindings, once a trigger has been used, it cannot be modified.