<Window x:Class="SRQC_DataTrigger_Command.MainWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"  
         Title="MainWindow" Height="350" Width="525">
     <StackPanel>
         <TextBox Text="" x:Name="input"/>
         <Button Content="Click">
             <i:Interaction.Triggers>
                 <i:EventTrigger EventName="Click">//在这里为Click事件,还要求上面的input的值为ABC,才执行这个事件
                     <i:InvokeCommandAction Command="{Binding OnAdd}" CommandParameter="1"></i:InvokeCommandAction>
                 </i:EventTrigger>
             </i:Interaction.Triggers>
         </Button>
     </StackPanel>
 </Window>
 谢谢

解决方案 »

  1.   

    直接在命令处理程序里判断是最方便的。
    如果要在xaml中处理,可以这样:<Window x:Class="SRQC_DataTrigger_Command.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
            xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
            Title="MainWindow" Height="350" Width="525"
        >
        <StackPanel>
            <TextBox Text="" x:Name="input"/>
            <Button Content="Click">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:Interaction.Behaviors>
                            <ei:ConditionBehavior>
                                <ei:ConditionalExpression>
                                    <ei:ComparisonCondition LeftOperand="{Binding Text, ElementName=input}" Operator="Equal" RightOperand="ABC"/>
                                </ei:ConditionalExpression>
                            </ei:ConditionBehavior>
                        </i:Interaction.Behaviors>
                        <i:InvokeCommandAction Command="{Binding OnAdd}" CommandParameter="1"></i:InvokeCommandAction>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
        </StackPanel>
    </Window>