wpf 使用触发器检查复选框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31059000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
checkbox checking using triggers
提问by trinadh
I have two checkboxes chkone,chktwo. when i am trying to check the first checkbox(chkone) i am disabling the second checkbox and ischeckd is true, but when i was executed disabling working properly but ischecked in not working?
我有两个复选框 chkone,chktwo。当我试图检查第一个复选框(chkone)时,我禁用了第二个复选框,并且 ischeckd 为真,但是当我执行时禁用正常工作但被检查无效?
<CheckBox x:Name="chkone"
Content="QA Review Mandatory" Margin="22,12,289,275"
IsChecked="{Binding Ischkone}"/>
<CheckBox x:Name="chktwo"
Content="Question Mandatory" HorizontalAlignment="Left"
Margin="22,85,0,201" IsChecked="{Binding Ischktwo}">
<CheckBox.Style>
<Style TargetType="CheckBox">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=chkone,Path=IsChecked}" Value="True">
<Setter Property="IsChecked" Value="True"/>
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=chkone,Path=IsChecked}" Value="False">
<Setter Property="IsChecked" Value="False"/>
<Setter Property="IsEnabled" Value="True"/>
</DataTrigger>
</Style.Triggers>
</Style>
</CheckBox.Style>
</CheckBox>
回答by prawin
Try below code and let me know if you are still facing issue,
尝试下面的代码,如果您仍然遇到问题,请告诉我,
<CheckBox x:Name="chkone"
Content="QA Review Mandatory" Margin="22,12,289,275"
IsChecked="{Binding Ischkone}"/>
<CheckBox x:Name="chktwo"
Content="Question Mandatory" HorizontalAlignment="Left"
Margin="22,85,0,201" >
<CheckBox.Style>
<Style TargetType="CheckBox">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=chkone,Path=IsChecked}" Value="True">
<Setter Property="IsChecked" Value="True"/>
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=chkone,Path=IsChecked}" Value="False">
<Setter Property="IsChecked" Value="False"/>
<Setter Property="IsEnabled" Value="True"/>
</DataTrigger>
</Style.Triggers>
</Style>
</CheckBox.Style>
</CheckBox>

