Click here to Skip to main content
15,179,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 21-Aug-12 1:56am
v2

   
v2
Comments
Kunjammu 21-Aug-12 6:59am
   
sorry..i want to do it using radiobutton. is there any solution?
ridoy 21-Aug-12 7:04am
   
yes,a fault from me..i updated it
Kunjammu 21-Aug-12 7:20am
   
thanks...i got solution from the second link given by you
You can use IValueConverter for this..
Have a look on the below code...

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


C#
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..
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900