WPF XAML 获取单选框选中值 - 示例代码
可以使用单选框的 'IsChecked' 属性来判断单选框是否选中,然后再获取其 'Content' 属性的值。
示例代码如下:
<StackPanel>
<RadioButton x:Name="rb1" Content="选项1" />
<RadioButton x:Name="rb2" Content="选项2" />
<Button Click="Button_Click" Content="获取选中值" />
</StackPanel>
private void Button_Click(object sender, RoutedEventArgs e)
{
if (rb1.IsChecked == true)
{
MessageBox.Show('选中了选项1');
}
else if (rb2.IsChecked == true)
{
MessageBox.Show('选中了选项2');
}
}
在按钮的 'Click' 事件中判断哪个单选框被选中,然后弹出对应的消息框。
原文地址: https://www.cveoy.top/t/topic/mSq8 著作权归作者所有。请勿转载和采集!