复选框的 WPF 分组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41363139/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:58:45  来源:igfitidea点击:

WPF grouping for checkboxes

wpfcheckbox

提问by Navya Sri

    <CheckBox Content="1" Margin="43,73,430,227" />
    <CheckBox  Content="2" Margin="123,73,359,227"/>
</Grid>

Above are my checkboxe. I need to group them. I f check 1 then 2 should be unchecked and vice versa. This should be done in xaml. Is there any property settings or xaml code to apply my requirement other than adding c# code.

上面是我的复选框。我需要将它们分组。如果选中 1,则 2 应取消选中,反之亦然。这应该在 xaml 中完成。除了添加 c# 代码之外,是否有任何属性设置或 xaml 代码可以应用我的要求。

回答by RQDQ

Have you tried using RadioButton?

您是否尝试过使用 RadioButton?

 <RadioButton GroupName="MyGroup" Content="1" Margin="43,73,430,227" />
 <RadioButton GroupName="MyGroup"  Content="2" Margin="123,73,359,227"/>

If you still need them to look like checkboxes, use this answer.

如果您仍然需要它们看起来像复选框,请使用此答案