using System; using System.Globalization; using System.Windows.Data; using System.Windows.Media; namespace HC_APTBS.Converters { /// /// Converts a CSS-style hex colour string (e.g. "#26C200") to a /// for use in WPF bindings. /// Returns for null or invalid input. /// [ValueConversion(typeof(string), typeof(SolidColorBrush))] public sealed class HexColorToBrushConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is string hex && !string.IsNullOrWhiteSpace(hex)) { try { return new SolidColorBrush((Color)ColorConverter.ConvertFromString(hex)); } catch { /* fall through */ } } return Brushes.Transparent; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotSupportedException(); } }