A project I am working on has an enum defined that has only two states. I am using a toggle button to switch the property value.
Using the value converter that I wrote for binding enums to a set of radio buttons does not work since it only changes the value one way due to the Binding.DoNothing.
Here is the enum to boolean converter used for the radio buttons that only changes the value in one direction:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value.Equals(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value.Equals(true) ? parameter : Binding.DoNothing;
}
As a workaround I modified this specifically for the enum that I am using as shown below by replacing Binding.DoNothing with MyEnum.Off in the ConvertBack method
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value.Equals(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value.Equals(true) ? parameter : MyEnum.Off;
}
Is there a better way to switch this enum value returned to enable the toggle button to switch the enum to the off state that would be reusable across different Enum types?