2016-11-25 41 views

回答

0

下面的代碼按預期工作:

<RadioButton Content="Boom" Command="{Binding MyCommand}" /> 

也就是說,如在常規Button情況下,MyCommand被激發你點擊一個RadioButton每次。如果您使用RadioButtons,這可以理解,可能不是您想要的。

更多有用將被傳遞一些類型的數據作爲CommandParameter知道哪個選項被選中:

​​

示例命令方法:

private ICommand _MyCommand; 
    public ICommand MyCommand 
    { 
     get { return _MyCommand ?? (_MyCommand = new DelegateCommand(a => MyCommandMethod(a))); } 
    } 

    private void MyCommandMethod(object item) 
    { 
     Console.WriteLine("Chosen element: " + (string)item); 
    } 
0

步驟1:添加System.Windows.Interactivity參考

步驟2:在XAML中添加命名空間xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

步驟3:

<RadioButton Content="Boom" IsEnabled="{Binding IsChecked, Converter={StaticResource InverseBooleanConverter}, RelativeSource={RelativeSource Mode=Self}}"> 
<i:Interaction.Triggers> 
     <i:EventTrigger EventName="Checked"> 
      <i:InvokeCommandAction Command="{Binding MyCommand}" /> 
     </i:EventTrigger> 
    </i:Interaction.Triggers> 
</RadioButton> 
相關問題