using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; using System.Windows.Media; using XP.Hardware.RaySource.Abstractions.Enums; namespace XP.Hardware.RaySource.Converters { /// /// 射线源状态转背景色转换器(径向渐变) /// public class RaySourceStatusToColorConverter : IValueConverter { /// /// 状态转颜色(不可用=灰色,关闭=绿色,开启=红色)- 中心渐变效果 /// public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is RaySourceStatus status) { return status switch { RaySourceStatus.Unavailable => CreateRadialGradient( Color.FromRgb(224, 224, 224), // 中心浅灰 Color.FromRgb(189, 189, 189)), // 边缘深灰 RaySourceStatus.Closed => CreateRadialGradient( Color.FromRgb(139, 195, 74), // 中心浅绿 #8BC34A Color.FromRgb(76, 175, 80)), // 边缘深绿 #4CAF50 RaySourceStatus.Opened => CreateRadialGradient( Color.FromRgb(255, 138, 128), // 中心浅红 #FF8A80 Color.FromRgb(244, 67, 54)), // 边缘深红 #F44336 _ => CreateRadialGradient( Color.FromRgb(224, 224, 224), // 中心浅灰 Color.FromRgb(189, 189, 189)) // 边缘深灰 }; } return CreateRadialGradient( Color.FromRgb(224, 224, 224), Color.FromRgb(189, 189, 189)); } /// /// 创建径向渐变画刷 /// private RadialGradientBrush CreateRadialGradient(Color centerColor, Color edgeColor) { var brush = new RadialGradientBrush(); brush.GradientOrigin = new System.Windows.Point(0.5, 0.5); brush.Center = new System.Windows.Point(0.5, 0.5); brush.RadiusX = 0.8; brush.RadiusY = 0.8; brush.GradientStops.Add(new GradientStop(centerColor, 0.0)); brush.GradientStops.Add(new GradientStop(edgeColor, 1.0)); return brush; } /// /// 反向转换(无需实现) /// public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } /// /// 状态转边框色转换器 /// public class RaySourceStatusToBorderColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is RaySourceStatus status) { return status switch { RaySourceStatus.Unavailable => new SolidColorBrush(Color.FromRgb(158, 158, 158)), // 深灰 #9E9E9E RaySourceStatus.Closed => new SolidColorBrush(Color.FromRgb(46, 125, 50)), // 深绿 #2E7D32 RaySourceStatus.Opened => new SolidColorBrush(Color.FromRgb(198, 40, 40)), // 深红 #C62828 _ => new SolidColorBrush(Color.FromRgb(153, 153, 153)) }; } return new SolidColorBrush(Color.FromRgb(153, 153, 153)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } /// /// 状态转滑块启用状态转换器 /// public class RaySourceStatusToSliderEnabledConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is RaySourceStatus status) { return status == RaySourceStatus.Opened; // 开启时滑块可用,关闭时禁用 } return false; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }