mirror of
https://github.com/jie65535/ChineseChess.git
synced 2024-07-27 18:55:00 +08:00
37 lines
948 B
C#
37 lines
948 B
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
|
|
namespace ChineseChess.GUI.Converters
|
|
{
|
|
public class EnumToBooleanConverter : IValueConverter
|
|
{
|
|
public Type EnumType { get; set; }
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (parameter is string enumString)
|
|
{
|
|
if (Enum.IsDefined(EnumType, value))
|
|
{
|
|
var enumValue = Enum.Parse(EnumType, enumString);
|
|
|
|
return enumValue.Equals(value);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (parameter is string enumString)
|
|
{
|
|
return Enum.Parse(EnumType, enumString);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|