ComboboxConverter.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Avalonia.Data.Converters;
  2. using System;
  3. using System.Collections;
  4. using System.Globalization;
  5. namespace SukiUI.Theme
  6. {
  7. public class PlusNineConverter : IValueConverter
  8. {
  9. public static readonly PlusNineConverter Instance = new();
  10. public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
  11. {
  12. double x = (double)value;
  13. if (x == 0)
  14. return 0;
  15. x += 9;
  16. return x;
  17. }
  18. public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
  19. {
  20. throw new NotSupportedException();
  21. }
  22. }
  23. public class BiggestItemConverter : IValueConverter
  24. {
  25. public static readonly BiggestItemConverter Instance = new();
  26. public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
  27. {
  28. IEnumerable? x = (IEnumerable?)value;
  29. if (x is null)
  30. return "";
  31. var s = "";
  32. foreach (var o in x)
  33. {
  34. if (o?.ToString()?.Length > s.ToString().Length)
  35. s = o.ToString();
  36. }
  37. return s;
  38. }
  39. public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
  40. {
  41. throw new NotSupportedException();
  42. }
  43. }
  44. public class BiggestItemListBoxConverter : IValueConverter
  45. {
  46. public static readonly BiggestItemConverter Instance = new();
  47. public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
  48. {
  49. IEnumerable? x = (IEnumerable?)value;
  50. if (x is null)
  51. return "";
  52. var s = "";
  53. foreach (var o in x)
  54. {
  55. if (o?.ToString()?.Length > s.ToString().Length)
  56. s = o.ToString();
  57. }
  58. return s;
  59. }
  60. public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
  61. {
  62. throw new NotSupportedException();
  63. }
  64. }
  65. }