TankStageConverters.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Avalonia.Data.Converters;
  2. using Avalonia.Media;
  3. using System;
  4. using System.Globalization;
  5. using YZWater.Core.Models;
  6. using YZWater.Core.Services;
  7. namespace YZWater.Avalonia.Converters;
  8. /// <summary>
  9. /// 液位工况档位(TankStage)转换器集合:
  10. /// <list type="bullet">
  11. /// <item><see cref="ToText"/> — 档位名称(随语言切换)</item>
  12. /// <item><see cref="ToBrush"/> — 档位警示色(停泵灰 / 启泵蓝绿 / 保护红)</item>
  13. /// </list>
  14. /// </summary>
  15. public static class TankStageConverters
  16. {
  17. /// <summary>档位名称(随语言切换)</summary>
  18. public static readonly IValueConverter ToText =
  19. new FuncValueConverter<TankStage, string>(stage => stage switch
  20. {
  21. TankStage.Protection => LanguageService.Instance.Get("TankStageProtection"),
  22. TankStage.Pump3 => LanguageService.Instance.Get("TankStagePump3"),
  23. TankStage.Pump2 => LanguageService.Instance.Get("TankStagePump2"),
  24. TankStage.Pump1 => LanguageService.Instance.Get("TankStagePump1"),
  25. _ => LanguageService.Instance.Get("TankStageStop"),
  26. });
  27. /// <summary>档位警示色:保护红 / 启泵琥珀 / 停泵灰绿</summary>
  28. public static readonly IValueConverter ToBrush =
  29. new FuncValueConverter<TankStage, IBrush>(stage => stage switch
  30. {
  31. TankStage.Protection => new SolidColorBrush(Color.Parse("#E53935")),
  32. TankStage.Pump3 => new SolidColorBrush(Color.Parse("#FF7043")),
  33. TankStage.Pump2 => new SolidColorBrush(Color.Parse("#FFB300")),
  34. TankStage.Pump1 => new SolidColorBrush(Color.Parse("#26A69A")),
  35. _ => new SolidColorBrush(Color.Parse("#78909C")),
  36. });
  37. /// <summary>档位文字前景色(深色区配白字,浅色区配深字)</summary>
  38. public static readonly IValueConverter ToForeground =
  39. new FuncValueConverter<TankStage, IBrush>(stage => stage is TankStage.Stop or TankStage.Pump1
  40. ? new SolidColorBrush(Color.Parse("#1B1F27"))
  41. : new SolidColorBrush(Colors.White));
  42. }