ThemeHelper.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Avalonia.Media;
  2. namespace YZWater.Avalonia.Controls;
  3. /// <summary>
  4. /// 主题资源辅助方法 - 直接缓存当前主题画刷
  5. /// </summary>
  6. internal static class ThemeHelper
  7. {
  8. public static event Action? ThemeChanged;
  9. public static void NotifyThemeChanged() => ThemeChanged?.Invoke();
  10. // ─── 当前主题画刷缓存 ───
  11. public static IBrush AppBg { get; private set; } = new SolidColorBrush(Color.Parse("#0A0E14"));
  12. public static IBrush SurfaceBg { get; private set; } = new SolidColorBrush(Color.Parse("#111820"));
  13. public static IBrush PanelBg { get; private set; } = new SolidColorBrush(Color.Parse("#0D1117"));
  14. public static IBrush Border { get; private set; } = new SolidColorBrush(Color.Parse("#1C2333"));
  15. public static IBrush TextPrimary { get; private set; } = new SolidColorBrush(Color.Parse("#E6EDF3"));
  16. public static IBrush TextSecondary { get; private set; } = new SolidColorBrush(Color.Parse("#9CA3AF"));
  17. public static IBrush TextTertiary { get; private set; } = new SolidColorBrush(Color.Parse("#6B7280"));
  18. public static IBrush TextDisabled { get; private set; } = new SolidColorBrush(Color.Parse("#4B5563"));
  19. public static IBrush Success { get; private set; } = new SolidColorBrush(Color.Parse("#00897B"));
  20. public static IBrush Warning { get; private set; } = new SolidColorBrush(Color.Parse("#F59E0B"));
  21. public static IBrush Danger { get; private set; } = new SolidColorBrush(Color.Parse("#EF4444"));
  22. public static IBrush Info { get; private set; } = new SolidColorBrush(Color.Parse("#3B82F6"));
  23. public static IBrush HeaderBg { get; private set; } = new SolidColorBrush(Color.Parse("#111820"));
  24. public static IBrush HeaderText { get; private set; } = new SolidColorBrush(Color.Parse("#E6EDF3"));
  25. public static IBrush HeaderSubtext { get; private set; } = new SolidColorBrush(Color.Parse("#9CA3AF"));
  26. public static IBrush NavBg { get; private set; } = new SolidColorBrush(Color.Parse("#111820"));
  27. /// <summary>
  28. /// 设置当前主题(由 App.axaml.cs 调用)
  29. /// </summary>
  30. public static void SetTheme(bool isDark)
  31. {
  32. Console.WriteLine($"[ThemeHelper] SetTheme: isDark={isDark}, current HeaderBg={((SolidColorBrush)HeaderBg).Color}");
  33. if (isDark)
  34. {
  35. AppBg = new SolidColorBrush(Color.Parse("#0A0E14"));
  36. SurfaceBg = new SolidColorBrush(Color.Parse("#111820"));
  37. PanelBg = new SolidColorBrush(Color.Parse("#0D1117"));
  38. Border = new SolidColorBrush(Color.Parse("#1C2333"));
  39. TextPrimary = new SolidColorBrush(Color.Parse("#E6EDF3"));
  40. TextSecondary = new SolidColorBrush(Color.Parse("#9CA3AF"));
  41. TextTertiary = new SolidColorBrush(Color.Parse("#6B7280"));
  42. TextDisabled = new SolidColorBrush(Color.Parse("#4B5563"));
  43. Success = new SolidColorBrush(Color.Parse("#00897B"));
  44. Warning = new SolidColorBrush(Color.Parse("#F59E0B"));
  45. Danger = new SolidColorBrush(Color.Parse("#EF4444"));
  46. Info = new SolidColorBrush(Color.Parse("#3B82F6"));
  47. HeaderBg = new SolidColorBrush(Color.Parse("#111820"));
  48. HeaderText = new SolidColorBrush(Color.Parse("#E6EDF3"));
  49. HeaderSubtext = new SolidColorBrush(Color.Parse("#9CA3AF"));
  50. NavBg = new SolidColorBrush(Color.Parse("#111820"));
  51. }
  52. else
  53. {
  54. AppBg = new SolidColorBrush(Color.Parse("#E5E7EB"));
  55. SurfaceBg = new SolidColorBrush(Color.Parse("#F3F4F6"));
  56. PanelBg = new SolidColorBrush(Color.Parse("#FFFFFF"));
  57. Border = new SolidColorBrush(Color.Parse("#9CA3AF"));
  58. TextPrimary = new SolidColorBrush(Color.Parse("#111827"));
  59. TextSecondary = new SolidColorBrush(Color.Parse("#4B5563"));
  60. TextTertiary = new SolidColorBrush(Color.Parse("#6B7280"));
  61. TextDisabled = new SolidColorBrush(Color.Parse("#9CA3AF"));
  62. Success = new SolidColorBrush(Color.Parse("#047857"));
  63. Warning = new SolidColorBrush(Color.Parse("#B45309"));
  64. Danger = new SolidColorBrush(Color.Parse("#B91C1C"));
  65. Info = new SolidColorBrush(Color.Parse("#1D4ED8"));
  66. HeaderBg = new SolidColorBrush(Color.Parse("#1F2937"));
  67. HeaderText = new SolidColorBrush(Color.Parse("#F9FAFB"));
  68. HeaderSubtext = new SolidColorBrush(Color.Parse("#9CA3AF"));
  69. NavBg = new SolidColorBrush(Color.Parse("#F9FAFB"));
  70. }
  71. ThemeChanged?.Invoke();
  72. }
  73. }