| | | 1 | | using Avalonia.Data.Converters; |
| | | 2 | | using System.Globalization; |
| | | 3 | | |
| | | 4 | | namespace LOCKnet.App.Converters; |
| | | 5 | | |
| | | 6 | | public sealed class StringToMaterialIconKindConverter : IValueConverter |
| | | 7 | | { |
| | 1 | 8 | | private static readonly Type? MaterialIconKindType = |
| | 1 | 9 | | Type.GetType("Material.Icons.MaterialIconKind, Material.Icons") ?? |
| | 1 | 10 | | Type.GetType("Material.Icons.MaterialIconKind, Material.Icons.Avalonia"); |
| | | 11 | | |
| | | 12 | | public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) |
| | 3 | 13 | | { |
| | 3 | 14 | | if (MaterialIconKindType is null) |
| | 0 | 15 | | { |
| | 0 | 16 | | return value?.ToString() ?? string.Empty; |
| | | 17 | | } |
| | | 18 | | |
| | 3 | 19 | | if (value is string text && Enum.TryParse(MaterialIconKindType, text, out var parsedKind)) |
| | 1 | 20 | | { |
| | 1 | 21 | | return parsedKind; |
| | | 22 | | } |
| | | 23 | | |
| | 2 | 24 | | return Enum.GetValues(MaterialIconKindType).GetValue(0) ?? value?.ToString() ?? string.Empty; |
| | 3 | 25 | | } |
| | | 26 | | |
| | | 27 | | public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) |
| | 1 | 28 | | { |
| | 1 | 29 | | return value?.ToString() ?? string.Empty; |
| | 1 | 30 | | } |
| | | 31 | | } |