将切换按钮绑定到两个命令

use*_*679 4 c# silverlight wpf xaml

我在silverlight应用程序中有一个切换按钮,如下所示:

<ToggleButton Content="ToggleButton" Margin="0,30,0,0" Style="{StaticResource ChkToggleButton}" />
Run Code Online (Sandbox Code Playgroud)

切换当前正在改变切换的视觉状态,仅此而已.
但是,我需要使用不同的命令绑定每个切换.例如:按下按钮1,command1再次按下运行和按钮,运行command2.

如何才能做到这一点?

Ana*_*uza 10

使用Triggers这样的目的:

<ToggleButton Content="ToggleButton" Margin="0,30,0,0" Style="{StaticResource ChkToggleButton}">
  <i:Interaction.Triggers>
        <i:EventTrigger EventName="Checked">
             <i:InvokeCommandAction Command="{Binding FirstCommand}"
                                    CommandParameter="{Binding SomeParameter}" />
        </i:EventTrigger>
        <i:EventTrigger EventName="Unchecked">
             <i:InvokeCommandAction Command="{Binding SecondCommand}"
                                    CommandParameter="{Binding AnotherParameter}" />
        </i:EventTrigger>
  </i:Interaction.Triggers>
</ToggleButton>  
Run Code Online (Sandbox Code Playgroud)

如果您没有Interactivity,可以通过安装Expression Blend SDK或作为NuGet包来获取它.