WPF:如何交互.Triggers添加位置

时间:2012-10-25 08:30:45

标签: c# wpf

  <StackPanel>
      <TextBox Text="" x:Name="input"/>
      <Button Content="Click">
          <i:Interaction.Triggers>
              <i:EventTrigger EventName="Click"><!-- TextBox has to contain "ABC" to get Button Click enabled this event-->
                  <i:InvokeCommandAction Command="{Binding OnAdd}" CommandParameter="1"></i:InvokeCommandAction>
              </i:EventTrigger>
              <i:EventTrigger EventName="Click"><!-- TextBox has to contain "123" to get Button Click enabled this event-->
                   <i:InvokeCommandAction Command="{Binding OnAdd2}" CommandParameter="1"></i:InvokeCommandAction>
               </i:EventTrigger>

          </i:Interaction.Triggers>
      </Button>
  </StackPanel>

我希望<i:EventTrigger EventName="Click"> TextBox必须包含“ABC”才能获得按钮点击启用此事件

1 个答案:

答案 0 :(得分:1)

我建议您在OnAdd Command中进行此处理。特别注意CanExecute方法。如果您启用Button,则会处理此按钮。你可以在这里阅读如何实现这个:

Commands Tutorial