BoolToArrowConverter.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Data;
  6. using System.Windows.Media;
  7. namespace TeamAAS.Converters
  8. {
  9. public class BoolToArrowConverter : IValueConverter
  10. {
  11. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  12. {
  13. if (value is bool collapsed && collapsed)
  14. return "▶";
  15. return "◀";
  16. }
  17. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  18. {
  19. throw new NotImplementedException();
  20. }
  21. }
  22. public class BoolToWidthConverter : IValueConverter
  23. {
  24. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  25. {
  26. if (value is bool collapsed && collapsed)
  27. return new GridLength(48);
  28. return new GridLength(280);
  29. }
  30. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  31. {
  32. throw new NotImplementedException();
  33. }
  34. }
  35. public class InvertBoolToVisibilityConverter : IValueConverter
  36. {
  37. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  38. {
  39. if (value is bool boolValue && boolValue)
  40. return Visibility.Collapsed;
  41. return Visibility.Visible;
  42. }
  43. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  44. {
  45. throw new NotImplementedException();
  46. }
  47. }
  48. /// <summary>
  49. /// 运行状态圆点颜色:true(运行中)=绿色,false=灰色。
  50. /// </summary>
  51. public class RunDotConverter : IValueConverter
  52. {
  53. private static readonly Brush Running = new SolidColorBrush(
  54. (Color)ColorConverter.ConvertFromString("#4CAF50"));
  55. private static readonly Brush Stopped = new SolidColorBrush(
  56. (Color)ColorConverter.ConvertFromString("#888888"));
  57. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  58. {
  59. return (value is bool b && b) ? Running : Stopped;
  60. }
  61. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  62. {
  63. throw new NotImplementedException();
  64. }
  65. }
  66. }