我有四个RadioButtons
在网格面板,但是当我这样做:如何获得的检查单选按钮的值在WPF
<GroupBox x:Name="radioButtons">
<RadioButton Content="1" Height="16" HorizontalAlignment="Left" Margin="10,45,0,0" Name="status1" VerticalAlignment="Top" />
<RadioButton Content="2" Height="16" HorizontalAlignment="Left" Margin="10,67,0,0" Name="status2" VerticalAlignment="Top" />
<RadioButton Content="3" Height="16" HorizontalAlignment="Left" Margin="10,89,0,0" Name="status3" VerticalAlignment="Top" />
<RadioButton Content="4" Height="16" HorizontalAlignment="Left" Margin="10,111,0,0" Name="status4" VerticalAlignment="Top" />
</GroupBox>
它说:
Error 1 The object 'GroupBox' already has a child and cannot add 'RadioButton'. 'GroupBox' can accept only one child.
而最后3 RadioButtons
说:
The property 'Content' is set more than once.
这有什么错我的GroupBox
?此外,在我的代码中,我想访问被检查的RadioButton
(最好是int
)。我该怎么做呢?我尝试着看Google,并且发现了很多结果,但是我无法理解其中的任何结果。
感谢它真的帮了我!你能指导我如何让代码签入谁? – DorZ11
我添加了一个链接到我的答案的最后部分。 http://wpftutorial.net/RadioButton.html是实现你所需要的一个相当不错的样本。 – Viv
添加了一个绑定到RadioButton的Checked事件中的函数。 intIndex应该是一个int值,前提是RadioButton的内容相应地设置为 – Viv