Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Radiobutton (two) (binding to boolean value)

I have a property of type boolean presented with checkbox.

I want to change that to two radiobuttons that bind on the same property presenting the value true/false.

How can that be done?

like image 265
no9 Avatar asked Jul 29 '10 10:07

no9


1 Answers

<RadioButton GroupName="Group1"               IsChecked="{Binding PropertyValue}" Content="Yes" /> <RadioButton GroupName="Group1"  Content="No"               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 } 
like image 178
Ragunathan Avatar answered Sep 20 '22 14:09

Ragunathan