2021-08-09 WPF控件专题 RadioButton控件详解
Posted 微软MVP Eleven
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021-08-09 WPF控件专题 RadioButton控件详解相关的知识,希望对你有一定的参考价值。
1.RadioButton控件介绍
同一组单选按钮,它们是互斥的关系
设置一个组名,不同组名的单选按钮,它们不具有互斥的关系
GroupName
2.具体案例
<Grid Name="grid1">
<RadioButton Content="管理员" GroupName="role" HorizontalAlignment="Left" IsChecked="True" Margin="43,101,0,0" VerticalAlignment="Top" Checked="RadioButton_Checked"/>
<RadioButton Content="学生" GroupName="role" HorizontalAlignment="Left" Margin="115,101,0,0" VerticalAlignment="Top" Checked="RadioButton_Checked"/>
<RadioButton Content="教师" GroupName="role" HorizontalAlignment="Left" Margin="221,101,0,0" VerticalAlignment="Top" Checked="RadioButton_Checked"/>
</Grid>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
RadioButton rbtn = new RadioButton();
rbtn.Content = "主任";
rbtn.GroupName = "role";
rbtn.IsChecked = false;
rbtn.HorizontalAlignment = HorizontalAlignment.Left;
rbtn.VerticalAlignment = VerticalAlignment.Top;
rbtn.Margin = new Thickness(320, 101, 0, 0);
// rbtn.Checked += RadioButton_Checked;
this.grid1.Children.Add(rbtn);
}
private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
MessageBox.Show((sender as RadioButton).Content.ToString());
}
以上是关于2021-08-09 WPF控件专题 RadioButton控件详解的主要内容,如果未能解决你的问题,请参考以下文章
2021-08-09 WPF控件专题 Label,TextBox,PasswordBox,Button控件介绍
2021-08-09 WPF控件专题 Window窗体属性和事件
2021-08-13 WPF控件专题 ComboBox 控件详解