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?
<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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With