gpt4 book ai didi

c# - 如何通过 C# 获取组中选定的单选按钮?

转载 作者:太空宇宙 更新时间:2023-11-03 17:13:48 27 4
gpt4 key购买 nike

如何通过 C# 获取位于面板(父容器)内的选定 Radiobutton 控件的索引?

如果解决方案需要的话,单选按钮的控件被命名为“acc”。

谢谢

最佳答案

<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();
}
}
}

所选按钮的索引将是对应于 (bool)radio.IsChecked 的“i”的值,因此您可以只记录此值并在其他地方使用它。

关于c# - 如何通过 C# 获取组中选定的单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7349998/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com