3

我们如何在 MultiDataTrigger 中进行比较?在普通的 DataTrigger 中,我们可以这样说:

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

但是我们如何在 MultiDataTrigger 条件下进行这样的比较呢?我搜索了,但找不到任何解决方案。请帮忙。谢谢。

4

2 回答 2

3

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>
于 2013-08-18T16:14:56.600 回答
0

您可以在绑定中创建一个转换器,根据您的需要返回 true 或 false。然后你应该把而不是'Value =“5”'

Value={StaticResource True}

你定义静态资源

<Application.Resources>
    ...
    <s:Boolean x:Key="True">True</s:Boolean>
    <s:Boolean x:Key="False">False</s:Boolean>
</Application.Resources>
于 2013-08-18T15:17:09.397 回答