我试图了解RadioButton
中的IsChecked
属性如何工作,因为我构建的自定义控件具有类似的行为。具有类似RadioButton IsChecked功能的自定义控件
我需要的信息是RadioButton
自动将IsChecked
变为false
当其他RadioButton
被选中。
见例如:
<StackPanel>
<RadioButton Content="Info 1" IsChecked="True" />
<RadioButton Content="Info 2" />
</StackPanel>
如果我在RadioButton
点击与"Info 2"
其它无线电自动变为选中。
但如果收音机处于diferent StackPanel
这样的:
<StackPanel>
<StackPanel>
<RadioButton Content="Info 1.1" IsChecked="True" />
<RadioButton Content="Info 1.2" />
</StackPanel>
<StackPanel>
<RadioButton Content="Info 2.1" IsChecked="True" />
<RadioButton Content="Info 2.2" />
</StackPanel>
</StackPanel>
当Info 1.1
点击了Info 2.1
保持检查。
我的自定义控件需要这种行为。最干净的方法是如何做到的?
也许你可以使用类似这样的解决方案:http://www.dragonshed.org/blog/2009/03/08/radiobuttons-in-a-datatemplate-in-silverlight /编辑:另外,你最后一个示例代码似乎是矛盾的。这听起来像你想要所有4个RadioButton被链接,但你默认为其中两个设置了“IsChecked = true”。 –