WPF中的RadioButton绑定 [英] RadioButton Binding in WPF

查看:82
本文介绍了WPF中的RadioButton绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个GenderRadioButton(男性和女性).如果我选择Male RadioButton,那么我要保存为true;如果选择Female RadioButton,则我要保存false.我该如何使用数据绑定

在此先感谢
Kunjammu

Hi,

I have two GenderRadioButtons (Male and Female). if i select Male RadioButton , then i want to save true and if Female RadioButton selected i want to save false. How can i do it using databinding

Thanks in advance
Kunjammu

推荐答案

WPF单选按钮和枚举值 [ ^ ]
http://wpftutorial.net/RadioButton.html [ http://www.phdesign.com.au/programming/wpf-radiobutton -binding-to-ischecked-property/ [ http://stackoverflow.com/questions/1317891/simple-wpf-radiobutton-binding [ ^ ]
WPF radio buttons and enumeration values[^]
http://wpftutorial.net/RadioButton.html[^]
http://www.phdesign.com.au/programming/wpf-radiobutton-binding-to-ischecked-property/[^]
http://stackoverflow.com/questions/1317891/simple-wpf-radiobutton-binding[^]


您可以为此使用IValueConverter..
看看下面的代码...

You can use IValueConverter for this..
Have a look on the below code...

<RadioButton GroupName="Group1" IsChecked="{Binding PropertyValue}" Content="Male" />
<RadioButton GroupName="Group1"  Content="Female" IsChecked="{Binding PropertyValue, Converter={StaticResource BoolInverterConverter}}" >





public class BoolInverterConverter : IValueConverter
{
    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value is bool)
        {
            return !(bool)value;
        }
        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value is bool)
        {
            return !(bool)value;
        }
        return value;
    }

    #endregion
}



这是出于示例目的...您必须修改代码..
如果您认为此方法有用..对其进行评分..



This is for your sample purpose...you have to modify the code..
If you find this as useful..rate it..


这篇关于WPF中的RadioButton绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆