I need a Style
under WPF that sets several properties when multiple conditions are fullfilled. However, one of my conditions is of type Not Equal To
. How should I change the below Style
so that the condition would become Not Equal To
? Can it be even achieved without IValueConverter
?
<Style>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<!--<Condition 1 here.../>-->
<!--<Condition 2 here.../>-->
<Condition Binding="{Binding Path=id}" Value="3"/>
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="Black"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
I would need the below but this of course don't work since Triggers only support Equal
operator.
<Style>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<!--<Condition 1 here.../>-->
<!--<Condition 2 here.../>-->
<Condition Binding="{Binding Path=id}" Value<>"3"/>
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="Black"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
You need an
IValueConverter
and some extra markup for this:And the converter:
Another option is to define default value as setter in style and then implement data trigger. In following code, the background value is always red except when value is 3