From 36f85325bc7242487f20eeb3fb2fe3142aa0872a Mon Sep 17 00:00:00 2001 From: robloo Date: Sat, 28 May 2022 12:28:23 -0400 Subject: [PATCH] Remove EnumValueEqualsConverter replaced by EnumToBooleanConverter --- .../Themes/Default/ColorSpectrum.xaml | 15 ++--- .../Themes/Fluent/ColorSpectrum.xaml | 15 ++--- .../Converters/EnumValueEqualsConverter.cs | 62 ------------------- 3 files changed, 16 insertions(+), 76 deletions(-) delete mode 100644 src/Avalonia.Controls/Converters/EnumValueEqualsConverter.cs diff --git a/src/Avalonia.Controls.ColorPicker/Themes/Default/ColorSpectrum.xaml b/src/Avalonia.Controls.ColorPicker/Themes/Default/ColorSpectrum.xaml index 78e6da8aa3..891e040e9f 100644 --- a/src/Avalonia.Controls.ColorPicker/Themes/Default/ColorSpectrum.xaml +++ b/src/Avalonia.Controls.ColorPicker/Themes/Default/ColorSpectrum.xaml @@ -1,10 +1,11 @@  - + @@ -24,26 +25,26 @@ IsHitTestVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" - IsVisible="{TemplateBinding Shape, Converter={StaticResource EnumValueEquals}, ConverterParameter='Box'}" + IsVisible="{TemplateBinding Shape, Converter={StaticResource EnumToBoolean}, ConverterParameter={x:Static controls:ColorSpectrumShape.Box}}" RadiusX="{TemplateBinding CornerRadius, Converter={StaticResource TopLeftCornerRadius}}" RadiusY="{TemplateBinding CornerRadius, Converter={StaticResource BottomRightCornerRadius}}" /> + IsVisible="{TemplateBinding Shape, Converter={StaticResource EnumToBoolean}, ConverterParameter={x:Static controls:ColorSpectrumShape.Ring}}" /> + IsVisible="{TemplateBinding Shape, Converter={StaticResource EnumToBoolean}, ConverterParameter={x:Static controls:ColorSpectrumShape.Ring}}" /> + IsVisible="{TemplateBinding Shape, Converter={StaticResource EnumToBoolean}, ConverterParameter={x:Static controls:ColorSpectrumShape.Ring}}" /> diff --git a/src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorSpectrum.xaml b/src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorSpectrum.xaml index ac8e2a9c06..779f228b97 100644 --- a/src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorSpectrum.xaml +++ b/src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorSpectrum.xaml @@ -1,10 +1,11 @@  - + @@ -24,26 +25,26 @@ IsHitTestVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" - IsVisible="{TemplateBinding Shape, Converter={StaticResource EnumValueEquals}, ConverterParameter='Box'}" + IsVisible="{TemplateBinding Shape, Converter={StaticResource EnumToBoolean}, ConverterParameter={x:Static controls:ColorSpectrumShape.Box}}" RadiusX="{TemplateBinding CornerRadius, Converter={StaticResource TopLeftCornerRadius}}" RadiusY="{TemplateBinding CornerRadius, Converter={StaticResource BottomRightCornerRadius}}" /> + IsVisible="{TemplateBinding Shape, Converter={StaticResource EnumToBoolean}, ConverterParameter={x:Static controls:ColorSpectrumShape.Ring}}" /> + IsVisible="{TemplateBinding Shape, Converter={StaticResource EnumToBoolean}, ConverterParameter={x:Static controls:ColorSpectrumShape.Ring}}" /> + IsVisible="{TemplateBinding Shape, Converter={StaticResource EnumToBoolean}, ConverterParameter={x:Static controls:ColorSpectrumShape.Ring}}" /> diff --git a/src/Avalonia.Controls/Converters/EnumValueEqualsConverter.cs b/src/Avalonia.Controls/Converters/EnumValueEqualsConverter.cs deleted file mode 100644 index abd0fe1dfd..0000000000 --- a/src/Avalonia.Controls/Converters/EnumValueEqualsConverter.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Globalization; -using Avalonia.Data.Converters; - -namespace Avalonia.Controls.Converters -{ - /// - /// Converter that checks if an enum value is equal to the given parameter enum value. - /// - public class EnumValueEqualsConverter : IValueConverter - { - /// - public object? Convert( - object? value, - Type targetType, - object? parameter, - CultureInfo culture) - { - // Note: Unlike string comparisons, null/empty is not supported - // Both 'value' and 'parameter' must exist and if both are missing they are not considered equal - if (value != null && - parameter != null) - { - Type type = value.GetType(); - - if (type.IsEnum) - { - var valueStr = value?.ToString(); - var paramStr = parameter?.ToString(); - - if (string.Equals(valueStr, paramStr, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - } - - /* - // TODO: When .net Standard 2.0 is no longer supported the code can be changed to below - // This is a little more type safe - if (type.IsEnum && - Enum.TryParse(type, value?.ToString(), true, out object? valueEnum) && - Enum.TryParse(type, parameter?.ToString(), true, out object? paramEnum)) - { - return valueEnum == paramEnum; - } - */ - } - - return false; - } - - /// - public object? ConvertBack( - object? value, - Type targetType, - object? parameter, - CultureInfo culture) - { - throw new System.NotImplementedException(); - } - } -}