namespace FieldLogger.Resources.Styles; public enum UlThemeMode { Default, Sunlight, } /// Applies generated semantic colors. Call on the UI thread after app resources initialize. public static class ThemeManager { private static readonly string[] SemanticColors = [ "Canvas", "Surface", "SurfaceRaised", "SurfaceStrong", "Text", "TextMuted", "Primary", "PrimaryPressed", "Accent", "Border", "Focus", "Map", "Success", "Warning", "Error", "Neutral", "Disabled", "OnStrong", "OnPrimary", "OnAccent", ]; public static UlThemeMode Current { get; private set; } = UlThemeMode.Default; public static void Apply(UlThemeMode mode) { var resources = Application.Current?.Resources ?? throw new InvalidOperationException("Application resources are not initialized."); var prefix = mode == UlThemeMode.Sunlight ? "UlSunlightColor" : "UlDefaultColor"; foreach (var name in SemanticColors) { if (!resources.TryGetValue($"{prefix}{name}", out var value) || value is not Color color) { throw new InvalidOperationException($"Generated theme token {prefix}{name} is missing."); } resources[$"UlColor{name}"] = color; resources[$"UlBrush{name}"] = new SolidColorBrush(color); } Current = mode; } }