30 lines
893 B
C#
30 lines
893 B
C#
using System;
|
|
using System.Globalization;
|
|
using Avalonia.Data.Converters;
|
|
|
|
namespace NexvaneHub.Converters;
|
|
|
|
/// <summary>
|
|
/// Compares a bound enum value's string representation against ConverterParameter.
|
|
/// Used for "is this nav item selected" / "is this section visible" bindings.
|
|
/// </summary>
|
|
public class EnumEqualsConverter : IValueConverter
|
|
{
|
|
public static readonly EnumEqualsConverter Instance = new();
|
|
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is null || parameter is null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return string.Equals(value.ToString(), parameter.ToString(), StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|