我認爲最好的方法仍然是通過使用CanCommandExecute執行Run按鈕所綁定的命令來使用VM方法。你也可以使用一些純粹的XAML。對於爲例:
<Grid xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions">
<i:Interaction.Triggers>
<i:EventTrigger SourceName="rbChoice1" EventName="Checked">
<i:Interaction.Behaviors>
<ei:ConditionBehavior>
<ei:ConditionalExpression ForwardChaining="Or">
<ei:ComparisonCondition LeftOperand="{Binding IsChecked, ElementName=rbChoice1}" RightOperand="True"/>
<ei:ComparisonCondition LeftOperand="{Binding IsChecked, ElementName=rbChoice2}" RightOperand="True"/>
<ei:ComparisonCondition LeftOperand="{Binding IsChecked, ElementName=rbChoice3}" RightOperand="True"/>
</ei:ConditionalExpression>
</ei:ConditionBehavior>
</i:Interaction.Behaviors>
<ei:ChangePropertyAction TargetName="btnRun" PropertyName="IsEnabled" Value="True"/>
</i:EventTrigger>
<i:EventTrigger SourceName="rbChoice2" EventName="Checked">
<i:Interaction.Behaviors>
<ei:ConditionBehavior>
<ei:ConditionalExpression ForwardChaining="Or">
<ei:ComparisonCondition LeftOperand="{Binding IsChecked, ElementName=rbChoice1}" RightOperand="True"/>
<ei:ComparisonCondition LeftOperand="{Binding IsChecked, ElementName=rbChoice2}" RightOperand="True"/>
<ei:ComparisonCondition LeftOperand="{Binding IsChecked, ElementName=rbChoice3}" RightOperand="True"/>
</ei:ConditionalExpression>
</ei:ConditionBehavior>
</i:Interaction.Behaviors>
<ei:ChangePropertyAction TargetName="btnRun" PropertyName="IsEnabled" Value="True"/>
</i:EventTrigger>
<i:EventTrigger SourceName="rbChoice3" EventName="Checked">
<i:Interaction.Behaviors>
<ei:ConditionBehavior>
<ei:ConditionalExpression ForwardChaining="Or">
<ei:ComparisonCondition LeftOperand="{Binding IsChecked, ElementName=rbChoice1}" RightOperand="True"/>
<ei:ComparisonCondition LeftOperand="{Binding IsChecked, ElementName=rbChoice2}" RightOperand="True"/>
<ei:ComparisonCondition LeftOperand="{Binding IsChecked, ElementName=rbChoice3}" RightOperand="True"/>
</ei:ConditionalExpression>
</ei:ConditionBehavior>
</i:Interaction.Behaviors>
<ei:ChangePropertyAction TargetName="btnRun" PropertyName="IsEnabled" Value="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width=" 300">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="10"/>
<RowDefinition/>
<RowDefinition Height="10"/>
<RowDefinition/>
<RowDefinition Height="10"/>
<RowDefinition/>
</Grid.RowDefinitions>
<RadioButton x:Name="rbChoice1" Grid.Row="0" Content="Choice 1"/>
<RadioButton x:Name="rbChoice2" Grid.Row="2" Content="Choice 2"/>
<RadioButton x:Name="rbChoice3" Grid.Row="4" Content="Choice 3"/>
<Button x:Name="btnRun" Grid.Row="6" Content="Run" IsEnabled="False"/>
</Grid>
</Grid>
不幸的是我:EventTrigger不採取路由事件,否則這可能只用一個EventTrigger來寫。但我認爲將其擴展爲接受路由事件應該很容易。
另一個解決方案是編寫一個MultiBindingConverter,它接收一個bools數組並對它們執行OR運算符並返回結果。通過這種方式,您可以將IsEnabled屬性綁定到無線電的所有IsChecked屬性。
Thx。這就是我所需要的。 –