Files
@ 8da5f6699d57
Branch filter:
Location: ATITD-Tools/Desert-Paint-Codex/Converters/EnumBooleanConverter.cs - annotation
8da5f6699d57
1006 B
text/x-csharp
Add constructor / setter to PaintColor to copy another paint color and assign a different name to it.
40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 |
using System;
using Avalonia.Data.Converters;
namespace DesertPaintCodex.Converters
{
public class EnumBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is not Enum en) return false;
string? parameterString = parameter.ToString();
if (parameterString == null) return false;
object parameterValue = Enum.Parse(value.GetType(), parameterString);
return parameterValue.Equals(value);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is not bool) return false;
string? parameterString = parameter.ToString();
if (parameterString == null) return false;
return Enum.Parse(targetType, parameterString);
}
}
}
|