WPF Multitrigger

This article discusses and demonstrates the implementation of a trigger in WPF which has multiple conditions.

Triggers in WPF are very important and handy features. Triggers and styles add to WPF's bag a rich set of functionality. Triggers are like event handlers which we define in XAML's DateTemplates and styles.Triggers allow us to define several Setter elements in a style. The trigger includes a condition, and when that condition is true, the Setters defined in the trigger will be applied. When the condition is false, the Setters are ignored.

Here is a sample trigger,


<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Visibility" Value="Collapsed" />
</Trigger>
</Style.Triggers>


The above example demonstrates a Style trigger which fires when the IsEnabled property is false. The resulting controls Visibility property will be set to Collapsed.

Moving ahead, what if our condition is based on multiple criteria? Here comes the use of MultiTriggers.

Here is a sample Multi-Trigger,

<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Content" Value="a" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Visibility" Value="Collapsed" />
</MultiTrigge>


The above trigger will fire when Content has a value of "a" and mouse is over the control.

Have fun.

Reference: http://abitsmart.com/?p=166


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: