如何在多数据触发器中进行比较

4

如何在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 Condition中呢?我搜索了一下,但没有找到任何解决方案。请帮忙。谢谢。
2个回答

3
您可以使用PropertyChangedTrigger (msdn):
在下面的示例中,我们检查Count属性的条件是否大于1且小于100:
<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>

如果需要绑定多个属性,是否有一种方法可以实现这一点?(即是否有类似于MultiDataTrigger的Expression Blend等效功能?)还是我们只能在MultiDataTrigger内使用转换器来实现? - GrantA

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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接