| 1 | using System.Globalization; |
| 2 | using Avalonia.Data.Converters; |
| 3 | using CascadeIDE.Features.UiChrome; |
| 4 | |
| 5 | namespace CascadeIDE.Views; |
| 6 | |
| 7 | /// <summary>Привязка <see cref="UiModeFamily"/> к bool: равенство переданному имени enum (ConverterParameter).</summary> |
| 8 | public sealed class UiModeFamilyEqualsConverter : IValueConverter |
| 9 | { |
| 10 | public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) |
| 11 | { |
| 12 | if (value is not UiModeFamily family) |
| 13 | return false; |
| 14 | var s = parameter?.ToString(); |
| 15 | if (string.IsNullOrEmpty(s)) |
| 16 | return false; |
| 17 | return Enum.TryParse<UiModeFamily>(s, ignoreCase: true, out var expected) && family == expected; |
| 18 | } |
| 19 | |
| 20 | public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => |
| 21 | throw new NotSupportedException(); |
| 22 | } |
| 23 | |
| 24 | /// <summary>True, если <see cref="UiModeFamily"/> **не** равен параметру (для <c>!IsPowerMode</c> и т.п.).</summary> |
| 25 | public sealed class UiModeFamilyNotEqualsConverter : IValueConverter |
| 26 | { |
| 27 | public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) |
| 28 | { |
| 29 | if (value is not UiModeFamily family) |
| 30 | return false; |
| 31 | var s = parameter?.ToString(); |
| 32 | if (string.IsNullOrEmpty(s)) |
| 33 | return false; |
| 34 | return Enum.TryParse<UiModeFamily>(s, ignoreCase: true, out var expected) && family != expected; |
| 35 | } |
| 36 | |
| 37 | public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => |
| 38 | throw new NotSupportedException(); |
| 39 | } |
| 40 | |