| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using Avalonia.Media;
- namespace YZWater.Avalonia.Controls;
- /// <summary>
- /// 主题资源辅助方法 - 直接缓存当前主题画刷
- /// </summary>
- internal static class ThemeHelper
- {
- public static event Action? ThemeChanged;
- public static void NotifyThemeChanged() => ThemeChanged?.Invoke();
- // ─── 当前主题画刷缓存 ───
- public static IBrush AppBg { get; private set; } = new SolidColorBrush(Color.Parse("#0A0E14"));
- public static IBrush SurfaceBg { get; private set; } = new SolidColorBrush(Color.Parse("#111820"));
- public static IBrush PanelBg { get; private set; } = new SolidColorBrush(Color.Parse("#0D1117"));
- public static IBrush Border { get; private set; } = new SolidColorBrush(Color.Parse("#1C2333"));
- public static IBrush TextPrimary { get; private set; } = new SolidColorBrush(Color.Parse("#E6EDF3"));
- public static IBrush TextSecondary { get; private set; } = new SolidColorBrush(Color.Parse("#9CA3AF"));
- public static IBrush TextTertiary { get; private set; } = new SolidColorBrush(Color.Parse("#6B7280"));
- public static IBrush TextDisabled { get; private set; } = new SolidColorBrush(Color.Parse("#4B5563"));
- public static IBrush Success { get; private set; } = new SolidColorBrush(Color.Parse("#00897B"));
- public static IBrush Warning { get; private set; } = new SolidColorBrush(Color.Parse("#F59E0B"));
- public static IBrush Danger { get; private set; } = new SolidColorBrush(Color.Parse("#EF4444"));
- public static IBrush Info { get; private set; } = new SolidColorBrush(Color.Parse("#3B82F6"));
- public static IBrush HeaderBg { get; private set; } = new SolidColorBrush(Color.Parse("#111820"));
- public static IBrush HeaderText { get; private set; } = new SolidColorBrush(Color.Parse("#E6EDF3"));
- public static IBrush HeaderSubtext { get; private set; } = new SolidColorBrush(Color.Parse("#9CA3AF"));
- public static IBrush NavBg { get; private set; } = new SolidColorBrush(Color.Parse("#111820"));
- /// <summary>
- /// 设置当前主题(由 App.axaml.cs 调用)
- /// </summary>
- public static void SetTheme(bool isDark)
- {
- Console.WriteLine($"[ThemeHelper] SetTheme: isDark={isDark}, current HeaderBg={((SolidColorBrush)HeaderBg).Color}");
- if (isDark)
- {
- AppBg = new SolidColorBrush(Color.Parse("#0A0E14"));
- SurfaceBg = new SolidColorBrush(Color.Parse("#111820"));
- PanelBg = new SolidColorBrush(Color.Parse("#0D1117"));
- Border = new SolidColorBrush(Color.Parse("#1C2333"));
- TextPrimary = new SolidColorBrush(Color.Parse("#E6EDF3"));
- TextSecondary = new SolidColorBrush(Color.Parse("#9CA3AF"));
- TextTertiary = new SolidColorBrush(Color.Parse("#6B7280"));
- TextDisabled = new SolidColorBrush(Color.Parse("#4B5563"));
- Success = new SolidColorBrush(Color.Parse("#00897B"));
- Warning = new SolidColorBrush(Color.Parse("#F59E0B"));
- Danger = new SolidColorBrush(Color.Parse("#EF4444"));
- Info = new SolidColorBrush(Color.Parse("#3B82F6"));
- HeaderBg = new SolidColorBrush(Color.Parse("#111820"));
- HeaderText = new SolidColorBrush(Color.Parse("#E6EDF3"));
- HeaderSubtext = new SolidColorBrush(Color.Parse("#9CA3AF"));
- NavBg = new SolidColorBrush(Color.Parse("#111820"));
- }
- else
- {
- AppBg = new SolidColorBrush(Color.Parse("#E5E7EB"));
- SurfaceBg = new SolidColorBrush(Color.Parse("#F3F4F6"));
- PanelBg = new SolidColorBrush(Color.Parse("#FFFFFF"));
- Border = new SolidColorBrush(Color.Parse("#9CA3AF"));
- TextPrimary = new SolidColorBrush(Color.Parse("#111827"));
- TextSecondary = new SolidColorBrush(Color.Parse("#4B5563"));
- TextTertiary = new SolidColorBrush(Color.Parse("#6B7280"));
- TextDisabled = new SolidColorBrush(Color.Parse("#9CA3AF"));
- Success = new SolidColorBrush(Color.Parse("#047857"));
- Warning = new SolidColorBrush(Color.Parse("#B45309"));
- Danger = new SolidColorBrush(Color.Parse("#B91C1C"));
- Info = new SolidColorBrush(Color.Parse("#1D4ED8"));
- HeaderBg = new SolidColorBrush(Color.Parse("#1F2937"));
- HeaderText = new SolidColorBrush(Color.Parse("#F9FAFB"));
- HeaderSubtext = new SolidColorBrush(Color.Parse("#9CA3AF"));
- NavBg = new SolidColorBrush(Color.Parse("#F9FAFB"));
- }
- ThemeChanged?.Invoke();
- }
- }
|