WPF 怎么判断哪个radioButton被选中
1个回答
展开全部
前台xaml:
<Grid>
<StackPanel>
<RadioButton x:Name="rbA" Content="选项A" GroupName="group1"></RadioButton>
<RadioButton x:Name="rbB" Content="选项B" GroupName="group1"></RadioButton>
</StackPanel>
</Grid>
后台:
放在构造函数中。
rbA.Checked += new RoutedEventHandler(radio_Checked);
rbB.Checked += new RoutedEventHandler(radio_Checked);
rbA.Unchecked += new RoutedEventHandler(radio_Unchecked);
rbB.Unchecked += new RoutedEventHandler(radio_Unchecked);
void radio_Unchecked(object sender, RoutedEventArgs e)
{
RadioButton btn = sender as RadioButton;
if (btn == null)
return;
if (btn.Name == "rbA")
{
}
if (btn.Name == "rbB")
{
}
}
void radio_Checked(object sender, RoutedEventArgs e)
{
// 同UnChecked判断。
}
<Grid>
<StackPanel>
<RadioButton x:Name="rbA" Content="选项A" GroupName="group1"></RadioButton>
<RadioButton x:Name="rbB" Content="选项B" GroupName="group1"></RadioButton>
</StackPanel>
</Grid>
后台:
放在构造函数中。
rbA.Checked += new RoutedEventHandler(radio_Checked);
rbB.Checked += new RoutedEventHandler(radio_Checked);
rbA.Unchecked += new RoutedEventHandler(radio_Unchecked);
rbB.Unchecked += new RoutedEventHandler(radio_Unchecked);
void radio_Unchecked(object sender, RoutedEventArgs e)
{
RadioButton btn = sender as RadioButton;
if (btn == null)
return;
if (btn.Name == "rbA")
{
}
if (btn.Name == "rbB")
{
}
}
void radio_Checked(object sender, RoutedEventArgs e)
{
// 同UnChecked判断。
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询