How to put a comparison in a multidatatrigger

3.1k Views Asked by At

How can we put a comparison in a MultiDataTrigger? Ina normal DataTrigger, we could put it as such:

<i:Interaction.Triggers>
       <ei:DataTrigger Binding="{Binding Count}" Comparison="LessThan" Value="5">
           <ei:ChangePropertyAction PropertyName="IsEnabled" Value="False"/>
       </ei:DataTrigger>
 </i:Interaction.Triggers>

But how do we put a comparison like this in a MultiDataTrigger condition? I searched, but couldn't find any solution. Please help. Thanks.

2

There are 2 best solutions below

1
On

You can use PropertyChangedTrigger (msdn):

In the below example we check condition is greater than 1 and less than 100 for Count property:

<TextBlock x:Name="textBlock" Background="Green" Text="{Binding Path=Count}">
    <i:Interaction.Triggers>
        <ei:PropertyChangedTrigger Binding="{Binding Path=Count}">
            <i:Interaction.Behaviors>
                <ei:ConditionBehavior>
                    <ei:ConditionalExpression>
                        <ei:ComparisonCondition LeftOperand="{Binding Count}" Operator="NotEqual" RightOperand="{x:Null}" />
                        <ei:ComparisonCondition LeftOperand="{Binding Count}" Operator="GreaterThan" RightOperand="1" />
                        <ei:ComparisonCondition LeftOperand="{Binding Count}" Operator="LessThan" RightOperand="100" />
                    </ei:ConditionalExpression>
                </ei:ConditionBehavior>                        
            </i:Interaction.Behaviors>
            <ei:ChangePropertyAction PropertyName="Background">
                <ei:ChangePropertyAction.Value>
                    <SolidColorBrush Color="Red"/>
                </ei:ChangePropertyAction.Value>
            </ei:ChangePropertyAction>
        </ei:PropertyChangedTrigger>            
    </i:Interaction.Triggers>
</TextBlock>
0
On

You can create a converter in the binding that returns true or false depending on what you want. Then instead of 'Value="5"', you should put

Value={StaticResource True}

and you define the static resource

<Application.Resources>
    ...
    <s:Boolean x:Key="True">True</s:Boolean>
    <s:Boolean x:Key="False">False</s:Boolean>
</Application.Resources>