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;
|
2024-12-23 11:57:20 +08:00
|
|
|
|
//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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|