BoolConverters.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Avalonia.Data.Converters;
  2. using Avalonia.Media;
  3. using System;
  4. using System.Globalization;
  5. namespace YZWater.Avalonia.Converters;
  6. /// <summary>
  7. /// 布尔值转换器集合
  8. /// </summary>
  9. public static class BoolConverters
  10. {
  11. /// <summary>
  12. /// true → #00897B (Success绿), false → #6B7280 (灰色)
  13. /// </summary>
  14. public static readonly IValueConverter ToBrush =
  15. new FuncValueConverter<bool, IBrush>(active =>
  16. active ? new SolidColorBrush(Color.Parse("#00897B"))
  17. : new SolidColorBrush(Color.Parse("#6B7280")));
  18. /// <summary>
  19. /// true → Bold, false → Normal
  20. /// </summary>
  21. public static readonly IValueConverter ToFontWeight =
  22. new FuncValueConverter<bool, FontWeight>(active =>
  23. active ? FontWeight.Bold : FontWeight.Normal);
  24. /// <summary>
  25. /// true → Disable, false → Enable (localized)
  26. /// </summary>
  27. public static readonly IValueConverter ToActiveText =
  28. new FuncValueConverter<bool, string>(active =>
  29. active ? YZWater.Core.Services.LanguageService.Instance.Get("Disable")
  30. : YZWater.Core.Services.LanguageService.Instance.Get("Enable"));
  31. /// <summary>
  32. /// true → "ON", false → "OFF"
  33. /// </summary>
  34. public static readonly IValueConverter ToText =
  35. new FuncValueConverter<bool, string>(active => active ? "ON" : "OFF");
  36. /// <summary>
  37. /// true → "中控", false → "屏控"
  38. /// </summary>
  39. public static readonly IValueConverter ToModeText =
  40. new FuncValueConverter<bool, string>(active => active ? "中控" : "屏控");
  41. }