using System; using System.Globalization; using System.Windows.Data; using System.Windows.Media; namespace ytLive.Helpers; /// Turns a "#RRGGBB" hex string into a brush, so a template can paint a colour /// swatch straight from the palette (TASK 63). /// /// Without it the UI would have to hand-build a brush in code — the hand-painted /// approach the theme forbids. A colour is data; the theme paints it. public class HexToBrushConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is not string hex || string.IsNullOrWhiteSpace(hex)) return Brushes.Transparent; try { var colour = (Color)ColorConverter.ConvertFromString(hex.Trim()); return new SolidColorBrush(colour); } catch (FormatException) { return Brushes.Transparent; } } public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException("A brush is not a hex value."); }