wpf Xaml获取单选框Content的值
可以使用单选框的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/bpuF 著作权归作者所有。请勿转载和采集!