using System; using System.Globalization; using System.Windows.Data; namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils { public class FlagEnumConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var flag = (WireFlagType)value; if (!Enum.IsDefined(typeof(WireFlagType), flag)) { return false; } return flag == (WireFlagType)parameter; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value is not bool isChecked) { throw new InvalidOperationException("The value must be a bool"); } return isChecked ? (WireFlagType)parameter : Binding.DoNothing; } } }