检查单选按钮

时间:2012-01-26 23:04:36

标签: windows-phone-7

我有一个RadioButton列表: RadioButton1 RadioButton2 RadioButton3 我想使用变量“检查”这个RadioButton中的一个: string nameCheckBox =“RadioButton”+1; 最后我想做:nameCheckBox.IsChecked = true;

有可能吗?

1 个答案:

答案 0 :(得分:4)

是的,但你必须确保每个RadioButton都有一个名字或一个x:名称

int index = 1; // 1, 2 or 3 in your case
object element = FindName(string.Concat("RadioButton", index));
if (element != null && element.GetType() == typeof(RadioButton))
    ((RadioButton)element).IsChecked = true;

你可以为CheckBox做同样的事情,只需用CheckBox替换RadioButton

相关问题