KeyValueConverter.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Avalonia.Data.Converters;
  2. using Ryujinx.Common.Configuration.Hid;
  3. using Ryujinx.Common.Configuration.Hid.Controller;
  4. using System;
  5. using System.Globalization;
  6. namespace Ryujinx.Ava.UI.Helpers
  7. {
  8. internal class KeyValueConverter : IValueConverter
  9. {
  10. public static KeyValueConverter Instance = new();
  11. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  12. {
  13. if (value == null)
  14. {
  15. return null;
  16. }
  17. return value.ToString();
  18. }
  19. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  20. {
  21. object key = null;
  22. if (value != null)
  23. {
  24. if (targetType == typeof(Key))
  25. {
  26. key = Enum.Parse<Key>(value.ToString());
  27. }
  28. else if (targetType == typeof(GamepadInputId))
  29. {
  30. key = Enum.Parse<GamepadInputId>(value.ToString());
  31. }
  32. else if (targetType == typeof(StickInputId))
  33. {
  34. key = Enum.Parse<StickInputId>(value.ToString());
  35. }
  36. }
  37. return key;
  38. }
  39. }
  40. }