WPF XAML 获取单选框 Content 值
你可以使用 RadioButton 的 IsChecked 属性来判断单选框是否被选中,如果被选中则可以使用 Content 属性来获取其值。
例如,如果你有三个单选框,分别是 rbOption1、rbOption2、rbOption3,你可以使用下面的代码来获取被选中的单选框的 Content 值:
if (rbOption1.IsChecked == true)
{
string selectedOption = rbOption1.Content.ToString();
}
else if (rbOption2.IsChecked == true)
{
string selectedOption = rbOption2.Content.ToString();
}
else if (rbOption3.IsChecked == true)
{
string selectedOption = rbOption3.Content.ToString();
}
在上面的代码中,我们首先检查每个单选框是否被选中,如果是,则将其 Content 属性转换为字符串并存储在 selectedOption 变量中。
原文地址: https://www.cveoy.top/t/topic/mSq2 著作权归作者所有。请勿转载和采集!