@@ -69,7 +69,15 @@ private static void ApplicationThemeManager_Changed(ApplicationTheme currentAppl
69
69
return ;
70
70
}
71
71
72
- public static ApplicationTheme GetSystemTheme ( )
72
+ /// <summary>
73
+ /// Get the theme of the application (<seealso cref="ApplicationThemeManager.GetAppTheme"/>).
74
+ /// </summary>
75
+ /// <returns>
76
+ /// Only the following enum will be returned.
77
+ /// <para><see cref="ApplicationTheme.Dark"/></para>
78
+ /// <para><see cref="ApplicationTheme.Light"/></para>
79
+ /// </returns>
80
+ public static ApplicationTheme GetApplicationTheme ( )
73
81
{
74
82
using RegistryKey ? key = Registry . CurrentUser . OpenSubKey ( @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" ) ;
75
83
object ? registryValueObject = key ? . GetValue ( "AppsUseLightTheme" ) ;
@@ -84,12 +92,112 @@ public static ApplicationTheme GetSystemTheme()
84
92
return registryValue > 0 ? ApplicationTheme . Light : ApplicationTheme . Dark ;
85
93
}
86
94
95
+ /// <summary>
96
+ /// Get the theme of the system (<seealso cref="SystemThemeManager.GetCachedSystemTheme"/>).
97
+ /// </summary>
98
+ /// <returns>
99
+ /// Only the following enum will be returned.
100
+ /// <para><see cref="SystemTheme.Dark"/></para>
101
+ /// <para><see cref="SystemTheme.Light"/></para>
102
+ /// </returns>
103
+ public static SystemTheme GetSystemTheme ( )
104
+ {
105
+ return Get ( ) switch
106
+ {
107
+ SystemTheme . Dark or SystemTheme . HCBlack or SystemTheme . Glow or SystemTheme . CapturedMotion => SystemTheme . Dark ,
108
+ _ => SystemTheme . Light ,
109
+ } ;
110
+
111
+ static SystemTheme Get ( )
112
+ {
113
+ var currentTheme =
114
+ Registry . GetValue (
115
+ "HKEY_CURRENT_USER\\ SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Themes" ,
116
+ "CurrentTheme" ,
117
+ "aero.theme"
118
+ ) as string
119
+ ?? string . Empty ;
120
+
121
+ if ( ! string . IsNullOrEmpty ( currentTheme ) )
122
+ {
123
+ currentTheme = currentTheme . ToLower ( ) . Trim ( ) ;
124
+
125
+ // This may be changed in the next versions, check the Insider previews
126
+ if ( currentTheme . Contains ( "basic.theme" ) )
127
+ {
128
+ return SystemTheme . Light ;
129
+ }
130
+
131
+ if ( currentTheme . Contains ( "aero.theme" ) )
132
+ {
133
+ return SystemTheme . Light ;
134
+ }
135
+
136
+ if ( currentTheme . Contains ( "dark.theme" ) )
137
+ {
138
+ return SystemTheme . Dark ;
139
+ }
140
+
141
+ if ( currentTheme . Contains ( "hcblack.theme" ) )
142
+ {
143
+ return SystemTheme . HCBlack ;
144
+ }
145
+
146
+ if ( currentTheme . Contains ( "hcwhite.theme" ) )
147
+ {
148
+ return SystemTheme . HCWhite ;
149
+ }
150
+
151
+ if ( currentTheme . Contains ( "hc1.theme" ) )
152
+ {
153
+ return SystemTheme . HC1 ;
154
+ }
155
+
156
+ if ( currentTheme . Contains ( "hc2.theme" ) )
157
+ {
158
+ return SystemTheme . HC2 ;
159
+ }
160
+
161
+ if ( currentTheme . Contains ( "themea.theme" ) )
162
+ {
163
+ return SystemTheme . Glow ;
164
+ }
165
+
166
+ if ( currentTheme . Contains ( "themeb.theme" ) )
167
+ {
168
+ return SystemTheme . CapturedMotion ;
169
+ }
170
+
171
+ if ( currentTheme . Contains ( "themec.theme" ) )
172
+ {
173
+ return SystemTheme . Sunrise ;
174
+ }
175
+
176
+ if ( currentTheme . Contains ( "themed.theme" ) )
177
+ {
178
+ return SystemTheme . Flow ;
179
+ }
180
+ }
181
+
182
+ /*if (currentTheme.Contains("custom.theme"))
183
+ return ; custom can be light or dark*/
184
+ var rawSystemUsesLightTheme =
185
+ Registry . GetValue (
186
+ "HKEY_CURRENT_USER\\ SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Themes\\ Personalize" ,
187
+ "SystemUsesLightTheme" ,
188
+ 1
189
+ ) ?? 1 ;
190
+
191
+ return rawSystemUsesLightTheme is 0 ? SystemTheme . Dark : SystemTheme . Light ;
192
+ }
193
+ }
194
+
87
195
public static void Apply ( ApplicationTheme theme )
88
196
{
89
197
if ( theme == ApplicationTheme . Unknown )
90
198
{
91
199
// To change `Unknown` to `System`.
92
- theme = GetSystemTheme ( ) ;
200
+ theme = GetApplicationTheme ( ) ;
93
201
}
94
202
95
203
if ( ApplicationThemeManager . GetAppTheme ( ) != theme )
0 commit comments