| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using Avalonia.Data.Converters;
- using Avalonia.Media;
- using System;
- using System.Globalization;
- using YZWater.Core.Models;
- using YZWater.Core.Services;
- namespace YZWater.Avalonia.Converters;
- /// <summary>
- /// 液位工况档位(TankStage)转换器集合:
- /// <list type="bullet">
- /// <item><see cref="ToText"/> — 档位名称(随语言切换)</item>
- /// <item><see cref="ToBrush"/> — 档位警示色(停泵灰 / 启泵蓝绿 / 保护红)</item>
- /// </list>
- /// </summary>
- public static class TankStageConverters
- {
- /// <summary>档位名称(随语言切换)</summary>
- public static readonly IValueConverter ToText =
- new FuncValueConverter<TankStage, string>(stage => stage switch
- {
- TankStage.Protection => LanguageService.Instance.Get("TankStageProtection"),
- TankStage.Pump3 => LanguageService.Instance.Get("TankStagePump3"),
- TankStage.Pump2 => LanguageService.Instance.Get("TankStagePump2"),
- TankStage.Pump1 => LanguageService.Instance.Get("TankStagePump1"),
- _ => LanguageService.Instance.Get("TankStageStop"),
- });
- /// <summary>档位警示色:保护红 / 启泵琥珀 / 停泵灰绿</summary>
- public static readonly IValueConverter ToBrush =
- new FuncValueConverter<TankStage, IBrush>(stage => stage switch
- {
- TankStage.Protection => new SolidColorBrush(Color.Parse("#E53935")),
- TankStage.Pump3 => new SolidColorBrush(Color.Parse("#FF7043")),
- TankStage.Pump2 => new SolidColorBrush(Color.Parse("#FFB300")),
- TankStage.Pump1 => new SolidColorBrush(Color.Parse("#26A69A")),
- _ => new SolidColorBrush(Color.Parse("#78909C")),
- });
- /// <summary>档位文字前景色(深色区配白字,浅色区配深字)</summary>
- public static readonly IValueConverter ToForeground =
- new FuncValueConverter<TankStage, IBrush>(stage => stage is TankStage.Stop or TankStage.Pump1
- ? new SolidColorBrush(Color.Parse("#1B1F27"))
- : new SolidColorBrush(Colors.White));
- }
|