35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
|
|
namespace NetDocsForLLM.Converters
|
|
{
|
|
/// <summary>
|
|
/// Converts between an enum value and a boolean value for binding to radio buttons or checkboxes
|
|
/// </summary>
|
|
public class EnumBooleanConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (parameter == null || value == null)
|
|
return false;
|
|
|
|
string parameterString = parameter.ToString();
|
|
if (Enum.IsDefined(value.GetType(), value))
|
|
{
|
|
return value.ToString().Equals(parameterString, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (parameter == null || !(bool)value)
|
|
return null;
|
|
|
|
string parameterString = parameter.ToString();
|
|
return Enum.Parse(targetType, parameterString);
|
|
}
|
|
}
|
|
} |