Using MarkupExtension ValueConverters does not work
Posted: 21 Apr 2021, 17:03
I tried using a standard technique of declaring a ValueConverter as a MarkupExtension for easy use.
In WPF it works fine, in Noesis however I get this error in Unity:
This is how the converter is implemented and used:
Is this a bug?
In WPF it works fine, in Noesis however I get this error in Unity:
Code: Select all
[noesis] Assets/Scripts/MapEditor/Views/ShellView.xaml(24): Can't set 'VacuumBreather.Montreal.MapEditor.ViewModels.EnumComparisonConverter' on property 'Binding.Converter' of type 'IValueConverter'.Code: Select all
/// <summary>
/// Converts a boolean to an enum value specified as the converter parameter.
/// Use to bind in a group of radio buttons to an enum property.
/// </summary>
/// <seealso cref="MarkupExtension" />
/// <seealso cref="IValueConverter" />
public class EnumComparisonConverter : MarkupExtension, IValueConverter
{
#region Constants and Fields
private static readonly EnumComparisonConverter Instance = new EnumComparisonConverter();
#endregion
#region IValueConverter Implementation
/// <inheritdoc />
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.Equals(parameter);
}
/// <inheritdoc />
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.Equals(true) == true ? parameter : Binding.DoNothing;
}
#endregion
#region Public Methods
/// <inheritdoc />
public override object ProvideValue(IServiceProvider serviceProvider)
{
return Instance;
}
#endregion
}
Code: Select all
<RadioButton IsChecked="{Binding Path=SelectedMode,
Converter={viewModels:EnumComparisonConverter},
ConverterParameter={x:Static viewModels:PaintingMode.Terrain},
Mode=TwoWay}" />