// This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. // Copyright (C) Leszek Pomianowski and WPF UI Contributors. // All Rights Reserved. namespace WPFluent.Gallery.Helpers; internal sealed class EnumToBooleanConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (parameter is not string enumString) { throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName"); } if (!Enum.IsDefined(typeof(WPFluent.Appearance.ApplicationTheme), value)) { throw new ArgumentException("ExceptionEnumToBooleanConverterValueMustBeAnEnum"); } var enumValue = Enum.Parse(typeof(WPFluent.Appearance.ApplicationTheme), enumString); return enumValue.Equals(value); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (parameter is not string enumString) { throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName"); } return Enum.Parse(typeof(WPFluent.Appearance.ApplicationTheme), enumString); } }