EPLAN_PROD_Plugin/Sinvo.EplanHpD.Plugin.WPFUI/Converter/FlagEnumConverter.cs

33 lines
978 B
C#
Raw Normal View History

2024-12-05 14:37:31 +08:00
using Sinvo.EplanHpD.Plugin.WPFUI.Enum;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using System;
2024-10-24 18:01:26 +08:00
using System.Globalization;
using System.Windows.Data;
2024-12-05 14:37:31 +08:00
namespace Sinvo.EplanHpD.Plugin.WPFUI.Converter
2024-10-24 18:01:26 +08:00
{
public class FlagEnumConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var flag = (WireFlagType)value;
//if (!System.Enum.IsDefined(typeof(WireFlagType), flag))
//{
// return false;
//}
2024-10-24 18:01:26 +08:00
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;
}
}
}