将Feature/XP.Common和Feature/XP.Hardware分支合并至Develop/XP.forHardwareAndCommon,完善XPapp注册和相关硬件类库通用类库功能。
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace XP.Hardware.RaySource.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// 灯丝寿命百分比转颜色转换器 | Filament lifetime percentage to color converter
|
||||
/// 根据寿命使用百分比返回对应的颜色画刷:
|
||||
/// 低于 80% → 绿色 (#FF4CAF50)
|
||||
/// 80%-89% → 黄色 (#FFFFC107)
|
||||
/// 90% 及以上 → 红色 (#FFE53935)
|
||||
/// </summary>
|
||||
public class FilamentLifetimeColorConverter : IValueConverter
|
||||
{
|
||||
// 预定义颜色画刷(避免重复创建)| Pre-defined color brushes (avoid repeated creation)
|
||||
private static readonly SolidColorBrush GreenBrush = new(Color.FromArgb(0xFF, 0x4C, 0xAF, 0x50));
|
||||
private static readonly SolidColorBrush YellowBrush = new(Color.FromArgb(0xFF, 0xFF, 0xC1, 0x07));
|
||||
private static readonly SolidColorBrush RedBrush = new(Color.FromArgb(0xFF, 0xE5, 0x39, 0x35));
|
||||
|
||||
static FilamentLifetimeColorConverter()
|
||||
{
|
||||
// 冻结画刷以提升性能 | Freeze brushes for better performance
|
||||
GreenBrush.Freeze();
|
||||
YellowBrush.Freeze();
|
||||
RedBrush.Freeze();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将寿命百分比(0-100)转换为对应颜色画刷 | Convert lifetime percentage (0-100) to corresponding color brush
|
||||
/// </summary>
|
||||
/// <param name="value">寿命百分比值(double,0-100)| Lifetime percentage value (double, 0-100)</param>
|
||||
/// <param name="targetType">目标类型 | Target type</param>
|
||||
/// <param name="parameter">转换参数(未使用)| Converter parameter (unused)</param>
|
||||
/// <param name="culture">区域信息 | Culture info</param>
|
||||
/// <returns>对应颜色的 SolidColorBrush | SolidColorBrush of corresponding color</returns>
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not double percentage)
|
||||
{
|
||||
return GreenBrush;
|
||||
}
|
||||
|
||||
if (percentage >= 90)
|
||||
{
|
||||
return RedBrush;
|
||||
}
|
||||
|
||||
if (percentage >= 80)
|
||||
{
|
||||
return YellowBrush;
|
||||
}
|
||||
|
||||
return GreenBrush;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反向转换(不支持,单向绑定)| Reverse conversion (not supported, one-way binding)
|
||||
/// </summary>
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user