Created
June 1, 2023 18:44
-
-
Save 5cover/a8c94c71b270efa4dd7e6942dfab45c0 to your computer and use it in GitHub Desktop.
Converter used to efficiently deal with radio buttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Globalization; | |
using System.Windows.Data; | |
/// <summary>A converter based on equality comparisons between the value and the parameter.</summary> | |
public sealed class EqualsConverter : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |
=> Equals(value, parameter); | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | |
=> (bool)value | |
? parameter | |
: Binding.DoNothing; | |
} | |
// Example bindings | |
// <RadioButton Content="1" IsChecked="{Binding SomeIntProperty, Converter={StaticResource Equals}, ConverterParameter=1}"/> | |
// <RadioButton Content="2" IsChecked="{Binding SomeIntProperty, Converter={StaticResource Equals}, ConverterParameter=2}"/> | |
// <RadioButton Content="3" IsChecked="{Binding SomeIntProperty, Converter={StaticResource Equals}, ConverterParameter=3}"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment