-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemeManager.cs
More file actions
176 lines (151 loc) · 8.96 KB
/
ThemeManager.cs
File metadata and controls
176 lines (151 loc) · 8.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;
using ModernWpf;
namespace NodaStack
{
public static class ThemeManager
{
private static readonly Color DefaultAccentColor = Color.FromRgb(0, 122, 204);
public static event Action<bool>? ThemeChanged;
private static bool _isDarkTheme = false;
public static bool IsDarkTheme
{
get => _isDarkTheme;
set
{
if (_isDarkTheme != value)
{
_isDarkTheme = value;
ApplyTheme(value);
ThemeChanged?.Invoke(value);
}
}
}
public static void ApplyTheme(bool isDark)
{
var app = Application.Current;
if (app == null) return;
try
{
ModernWpf.ThemeManager.Current.ApplicationTheme = isDark ? ApplicationTheme.Dark : ApplicationTheme.Light;
ModernWpf.ThemeManager.Current.AccentColor = DefaultAccentColor;
if (isDark)
{
// Ultra Modern Dark Theme - Vibrant & Deep
app.Resources["BackgroundBrush"] = new SolidColorBrush(Color.FromRgb(15, 23, 42)); // #0F172A
app.Resources["SurfaceBrush"] = new SolidColorBrush(Color.FromRgb(30, 41, 59)); // #1E293B
app.Resources["CardBackgroundBrush"] = new SolidColorBrush(Color.FromRgb(51, 65, 85)); // #334155
app.Resources["CardBorderBrush"] = new SolidColorBrush(Color.FromRgb(71, 85, 105)); // #475569
app.Resources["TextPrimaryBrush"] = new SolidColorBrush(Color.FromRgb(248, 250, 252)); // #F8FAFC
app.Resources["TextSecondaryBrush"] = new SolidColorBrush(Color.FromRgb(203, 213, 225)); // #CBD5E1
app.Resources["PrimaryBrush"] = new SolidColorBrush(Color.FromRgb(0, 120, 212)); // #0078D4
app.Resources["PrimaryDarkBrush"] = new SolidColorBrush(Color.FromRgb(0, 90, 158)); // #005A9E
// Legacy support
app.Resources["ForegroundBrush"] = new SolidColorBrush(Colors.White);
app.Resources["ButtonBackgroundBrush"] = new SolidColorBrush(Color.FromRgb(64, 64, 64));
app.Resources["ButtonHoverBrush"] = new SolidColorBrush(Color.FromRgb(80, 80, 80));
app.Resources["BorderBrush"] = new SolidColorBrush(Color.FromRgb(80, 80, 80));
app.Resources["TextBoxBackgroundBrush"] = new SolidColorBrush(Color.FromRgb(56, 56, 56));
app.Resources["GroupBoxBackgroundBrush"] = new SolidColorBrush(Color.FromRgb(52, 52, 52));
app.Resources["ListViewBackgroundBrush"] = new SolidColorBrush(Color.FromRgb(56, 56, 56));
app.Resources["LogBackgroundBrush"] = new SolidColorBrush(Color.FromRgb(40, 40, 40));
app.Resources["StatusBarBackgroundBrush"] = new SolidColorBrush(Color.FromRgb(44, 44, 44));
}
else
{
// Ultra Modern Light Theme - Clean & Vibrant
app.Resources["BackgroundBrush"] = new SolidColorBrush(Colors.White);
app.Resources["SurfaceBrush"] = new SolidColorBrush(Color.FromRgb(241, 245, 249)); // #F1F5F9
app.Resources["CardBackgroundBrush"] = new SolidColorBrush(Colors.White);
app.Resources["CardBorderBrush"] = new SolidColorBrush(Color.FromRgb(226, 232, 240)); // #E2E8F0
app.Resources["TextPrimaryBrush"] = new SolidColorBrush(Color.FromRgb(15, 23, 42)); // #0F172A
app.Resources["TextSecondaryBrush"] = new SolidColorBrush(Color.FromRgb(100, 116, 139)); // #64748B
app.Resources["PrimaryBrush"] = new SolidColorBrush(Color.FromRgb(0, 120, 212)); // #0078D4
app.Resources["PrimaryDarkBrush"] = new SolidColorBrush(Color.FromRgb(0, 90, 158)); // #005A9E
// Legacy support
app.Resources["ForegroundBrush"] = new SolidColorBrush(Colors.Black);
app.Resources["ButtonBackgroundBrush"] = new SolidColorBrush(Color.FromRgb(240, 240, 240));
app.Resources["ButtonHoverBrush"] = new SolidColorBrush(Color.FromRgb(230, 230, 230));
app.Resources["BorderBrush"] = new SolidColorBrush(Color.FromRgb(200, 200, 200));
app.Resources["TextBoxBackgroundBrush"] = new SolidColorBrush(Colors.White);
app.Resources["GroupBoxBackgroundBrush"] = new SolidColorBrush(Color.FromRgb(250, 250, 250));
app.Resources["ListViewBackgroundBrush"] = new SolidColorBrush(Colors.White);
app.Resources["LogBackgroundBrush"] = new SolidColorBrush(Colors.Black);
app.Resources["StatusBarBackgroundBrush"] = new SolidColorBrush(Color.FromRgb(240, 240, 240));
}
ApplyButtonStyle();
ApplyTextBoxStyle();
ApplyListViewStyle();
ApplyGroupBoxStyle();
ApplyTextBlockStyle();
}
catch (Exception ex)
{
Console.WriteLine($"Error applying theme: {ex.Message}");
}
}
private static void ApplyButtonStyle()
{
var app = Application.Current;
if (app == null) return;
var buttonStyle = new Style(typeof(Button));
buttonStyle.Setters.Add(new Setter(Button.BackgroundProperty, app.Resources["ButtonBackgroundBrush"]));
buttonStyle.Setters.Add(new Setter(Button.ForegroundProperty, app.Resources["ForegroundBrush"]));
buttonStyle.Setters.Add(new Setter(Button.BorderBrushProperty, app.Resources["BorderBrush"]));
buttonStyle.Setters.Add(new Setter(Button.PaddingProperty, new Thickness(5)));
buttonStyle.Setters.Add(new Setter(Button.MarginProperty, new Thickness(2)));
buttonStyle.Setters.Add(new Setter(Control.FontSizeProperty, 12.0));
var trigger = new Trigger { Property = Button.IsMouseOverProperty, Value = true };
trigger.Setters.Add(new Setter(Button.BackgroundProperty, app.Resources["ButtonHoverBrush"]));
buttonStyle.Triggers.Add(trigger);
app.Resources[typeof(Button)] = buttonStyle;
}
private static void ApplyTextBoxStyle()
{
var app = Application.Current;
if (app == null) return;
var textBoxStyle = new Style(typeof(TextBox));
textBoxStyle.Setters.Add(new Setter(TextBox.BackgroundProperty, app.Resources["TextBoxBackgroundBrush"]));
textBoxStyle.Setters.Add(new Setter(TextBox.ForegroundProperty, app.Resources["ForegroundBrush"]));
textBoxStyle.Setters.Add(new Setter(TextBox.BorderBrushProperty, app.Resources["BorderBrush"]));
textBoxStyle.Setters.Add(new Setter(Control.FontSizeProperty, 12.0));
app.Resources[typeof(TextBox)] = textBoxStyle;
}
private static void ApplyListViewStyle()
{
var app = Application.Current;
if (app == null) return;
var listViewStyle = new Style(typeof(ListView));
listViewStyle.Setters.Add(new Setter(ListView.BackgroundProperty, app.Resources["ListViewBackgroundBrush"]));
listViewStyle.Setters.Add(new Setter(ListView.ForegroundProperty, app.Resources["ForegroundBrush"]));
listViewStyle.Setters.Add(new Setter(ListView.BorderBrushProperty, app.Resources["BorderBrush"]));
app.Resources[typeof(ListView)] = listViewStyle;
}
private static void ApplyGroupBoxStyle()
{
var app = Application.Current;
if (app == null) return;
var groupBoxStyle = new Style(typeof(GroupBox));
groupBoxStyle.Setters.Add(new Setter(GroupBox.BackgroundProperty, app.Resources["GroupBoxBackgroundBrush"]));
groupBoxStyle.Setters.Add(new Setter(GroupBox.ForegroundProperty, app.Resources["ForegroundBrush"]));
groupBoxStyle.Setters.Add(new Setter(GroupBox.BorderBrushProperty, app.Resources["BorderBrush"]));
app.Resources[typeof(GroupBox)] = groupBoxStyle;
}
private static void ApplyTextBlockStyle()
{
var app = Application.Current;
if (app == null) return;
var textBlockStyle = new Style(typeof(TextBlock));
textBlockStyle.Setters.Add(new Setter(TextBlock.ForegroundProperty, app.Resources["ForegroundBrush"]));
textBlockStyle.Setters.Add(new Setter(TextBlock.FontSizeProperty, 12.0));
app.Resources[typeof(TextBlock)] = textBlockStyle;
}
public static void Initialize(bool isDarkTheme)
{
_isDarkTheme = isDarkTheme;
ApplyTheme(isDarkTheme);
}
}
}