从单选按钮选择中取消选中并禁用复选框

时间:2013-11-20 20:47:45

标签: silverlight xaml silverlight-5.0

所以我有一个radio group有两个radio buttons,还有一个checkbox tadiobutton2 被选中时,我希望checkbox成为enabled,当选择 radioButton1 时,我希望成为disabled

要做到这一点,我向x:Name提供radioButton2类似的问题,然后像我这样设置IsEnabled的{​​{1}}:

checkbox

现在想象他们点击IsEnabled="{Binding IsChecked, ElementName = blah, Mode=TwoWay}" ,然后将radiobutton2标记为checkbox,然后点击 radioButton1 。 我还想做的是取消选中复选框,当他们返回并选择 radiobutton1

我该怎么做?

注意:Checked IsChecked已经有一些绑定代码到了复杂的东西!(我想从EF拉出来)从现有的代码开始,所以我不想打破它。< / p>

1 个答案:

答案 0 :(得分:0)

对于像DataTrigger这样的人来说,这听起来不错。

namespaces;
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"


    <StackPanel>
       <RadioButton x:Name="Radio1" RadioGroupName="blah" Content="I can make that thingy Disabled"/>
       <RadioButton x:Name="Radio2" RadioGroupName="blah" Content="I can make that thingy Enabled"/>

       <CheckBox IsChecked="{Binding Blahblahblah}">
         <i:Interaction.Triggers>
            <ei:DataTrigger Value="False"
                            Binding="{Binding IsChecked, ElementName=Radio1}">
                <ei:ChangePropertyAction PropertyName="IsEnabled"
                                         Value="False" />
            </ei:DataTrigger>
            <ei:DataTrigger Value="True"
                            Binding="{Binding IsChecked, ElementName=Radio2}">
                <ei:ChangePropertyAction PropertyName="IsEnabled"
                                         Value="True" />
            </ei:DataTrigger>
         </i:Interaction.Triggers>
       </CheckBox>
    </StackPanel>

然而,只要记住amigo,你就会问到人们通常会在哪些地方开始向你推荐this article。这里的问题通常少于“我如何”,而更多的是“为什么这样”类型,如果你明白我的意思,无论哪种方式希望这有帮助。欢呼声。

相关问题