Sev*_*ays 1 .net c# silverlight radio-button windows-phone-7
如何通过c#获取位于面板(父容器)内的所选Radiobutton控件的索引?
如果解决方案需要,Radiobuttons的控制命名为"acc".
谢谢
Kre*_*epN 12
<StackPanel x:Name="panel" Orientation="Vertical">
<RadioButton x:Name="1"></RadioButton>
<RadioButton x:Name="2"></RadioButton>
<RadioButton x:Name="3"></RadioButton>
<RadioButton x:Name="4"></RadioButton>
...
<RadioButton x:Name="10"></RadioButton>
</StackPanel>
for (int i = 0; i < this.panel.Children.Count; i++)
{
if (this.panel.Children[i].GetType().Name == "RadioButton")
{
RadioButton radio = (RadioButton)this.panel.Children[i];
if ((bool)radio.IsChecked)
{
this.txt.Text ="the check radio button is:"+ radio.Name.ToString();
}
}
}
Run Code Online (Sandbox Code Playgroud)
所选按钮的索引将是对应于(bool)radio的"i"的值.IsChecked为true,因此您可以记录此值并在其他地方使用它.
归档时间: |
|
查看次数: |
11940 次 |
最近记录: |