GlyphValueConverter.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Avalonia.Data;
  2. using Avalonia.Markup.Xaml;
  3. using FluentAvalonia.UI.Controls;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Ryujinx.Ava.Ui.Controls
  7. {
  8. public class GlyphValueConverter : MarkupExtension
  9. {
  10. private string _key;
  11. private static Dictionary<Glyph, string> _glyphs = new Dictionary<Glyph, string>
  12. {
  13. { Glyph.List, char.ConvertFromUtf32((int)Symbol.List).ToString() },
  14. { Glyph.Grid, char.ConvertFromUtf32((int)Symbol.ViewAll).ToString() },
  15. { Glyph.Chip, char.ConvertFromUtf32(59748).ToString() }
  16. };
  17. public GlyphValueConverter(string key)
  18. {
  19. _key = key;
  20. }
  21. public string this[string key]
  22. {
  23. get
  24. {
  25. if (_glyphs.TryGetValue(Enum.Parse<Glyph>(key), out var val))
  26. {
  27. return val;
  28. }
  29. return string.Empty;
  30. }
  31. }
  32. public override object ProvideValue(IServiceProvider serviceProvider)
  33. {
  34. Avalonia.Markup.Xaml.MarkupExtensions.ReflectionBindingExtension binding = new($"[{_key}]")
  35. {
  36. Mode = BindingMode.OneWay,
  37. Source = this
  38. };
  39. return binding.ProvideValue(serviceProvider);
  40. }
  41. }
  42. }