WPF 怎么样判断哪个radioButton被选中?小弟穷,分少

.Net技术 码拜 8年前 (2016-05-14) 2234次浏览
穷人一个,分少。
求高手详解
解决方案

10

if (this.radiobutton3.IsChecked==true){
‘选中
}
else{
‘未选中
}

10

前台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判断。
        }

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明WPF 怎么样判断哪个radioButton被选中?小弟穷,分少
喜欢 (0)
[1034331897@qq.com]
分享 (0)