Friday, October 2, 2009

WPF #5 - Styling using MultiTrigger (MultiCondition setter)

Hi again, I noticed that I'm not explaining my tips that much, I wonder if this is happening due to the fact that I've only posted quick tips or if it is an actual issue.

Well, I'm more an example guy than a theory guy, for me is always easy to understand using examples than any other way. So if anyone read one of the tips and didn't understand it, please leave a comment so I can try to explain it better.

Now, this post tip, how to use MultiTrigger (or MultiConditions setters) in WPF, the following example pretty much explains itself:

<Style targettype="{x:Type Button}">
...
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="Content" Value="{x:Null}" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Yellow" />
</MultiTrigger>
</Style.Triggers>
</Style>

In this code I'm setting the background of a Button only when the mouse is over and the Content is not filled, don't ask me why I'm doing that, it's just an example, probably taken by the source url and used for something else!

Source: WPF Styles and Control Templates

Leave a comment if you guys have any questions.