| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using System;
- using System.Globalization;
- using System.Windows;
- using System.Windows.Data;
- using System.Windows.Media;
- namespace SWRIS.Converters
- {
- public class ColorStringToHoverBackgroundConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value is string colorString && !string.IsNullOrEmpty(colorString))
- {
- try
- {
- // 移除#号并确保6位十六进制
- string hex = colorString.TrimStart('#');
- if (hex.Length == 6)
- {
- return $"#1A{hex}"; // 添加透明度
- }
- }
- catch
- {
- return DependencyProperty.UnsetValue;
- }
- }
- return DependencyProperty.UnsetValue;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- public class ColorStringToHoverBorderBrushConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value is string colorString && !string.IsNullOrEmpty(colorString))
- {
- try
- {
- string hex = colorString.TrimStart('#');
- if (hex.Length == 6)
- {
- return $"#4D{hex}"; // 添加透明度
- }
- }
- catch
- {
- return DependencyProperty.UnsetValue;
- }
- }
- return DependencyProperty.UnsetValue;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- public class ColorStringToCheckedBackgroundConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value is string colorString && !string.IsNullOrEmpty(colorString))
- {
- try
- {
- string hex = colorString.TrimStart('#');
- if (hex.Length == 6)
- {
- return $"#4C{hex}"; // 添加透明度
- }
- }
- catch
- {
- return DependencyProperty.UnsetValue;
- }
- }
- return DependencyProperty.UnsetValue;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- }
|