Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将切换按钮绑定到两个命令_C#_Wpf_Silverlight_Xaml - Fatal编程技术网

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

C# 将切换按钮绑定到两个命令,c#,wpf,silverlight,xaml,C#,Wpf,Silverlight,Xaml,我在silverlight应用程序中有一个切换按钮,如下所示: <ToggleButton Content="ToggleButton" Margin="0,30,0,0" Style="{StaticResource ChkToggleButton}" /> 切换当前正在更改切换的视觉状态,仅此而已。 但是,我需要用不同的命令绑定每个切换。例如:在按下按钮1时,运行command1,在再次按下按钮时,运行command2 如何做到这一点?使用单个命令并跟踪切换状态 拥有一个v

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

<ToggleButton Content="ToggleButton" Margin="0,30,0,0" Style="{StaticResource ChkToggleButton}" />

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


如何做到这一点?

使用单个命令并跟踪切换状态

拥有一个viewmodel(最好是,或一些codebehind),让它使用这两个输入来决定实际需要做什么。

用于以下目的:

<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>  


如果您没有
交互性
,可以通过安装或作为一个组件来获得它。

我当时不知道映射到了什么xmlns,所以我查找了可能不知道的内容。它是System.Windows.Interactive,位于Blend SDK中。你可以在这里找到它: