@@ -50,7 +50,7 @@ public sealed partial class Application
50
50
51
51
private const string DarkModeKeyPath = "HKEY_CURRENT_USER\\ SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Themes\\ Personalize" ;
52
52
private const string DarkModeKey = "AppsUseLightTheme" ;
53
- private const int DarkModeNotAvailable = - 1 ;
53
+ private const int SystemDarkModeDisabled = 1 ;
54
54
55
55
/// <summary>
56
56
/// Events the user can hook into
@@ -283,6 +283,12 @@ public static void SetColorMode(SystemColorMode systemColorMode)
283
283
return ;
284
284
}
285
285
286
+ if ( GetSystemColorModeInternal ( ) != SystemDarkModeDisabled )
287
+ {
288
+ s_systemColorMode = SystemColorMode . Dark ;
289
+ return ;
290
+ }
291
+
286
292
s_systemColorMode = SystemColorMode . Classic ;
287
293
}
288
294
finally
@@ -358,20 +364,16 @@ private static int GetSystemColorModeInternal()
358
364
359
365
int systemColorMode = DarkModeNotAvailable ;
360
366
361
- // Dark mode is supported when we are >= W11/22000
362
- // Technically, we could go earlier, but then the APIs we're using weren't officially public.
363
- if ( OsVersion . IsWindows11_OrGreater ( ) )
367
+ try
368
+ {
369
+ // 0 for dark mode and |1| for light mode.
370
+ systemColorMode = Math . Abs ( ( Registry . GetValue (
371
+ keyName : DarkModeKeyPath ,
372
+ valueName : DarkModeKey ,
373
+ defaultValue : SystemDarkModeDisabled ) as int ? ) ?? systemColorMode ) ;
374
+ }
375
+ catch ( Exception ex ) when ( ! ex . IsCriticalException ( ) )
364
376
{
365
- try
366
- {
367
- systemColorMode = ( Registry . GetValue (
368
- keyName : DarkModeKeyPath ,
369
- valueName : DarkModeKey ,
370
- defaultValue : DarkModeNotAvailable ) as int ? ) ?? systemColorMode ;
371
- }
372
- catch ( Exception ex ) when ( ! ex . IsCriticalException ( ) )
373
- {
374
- }
375
377
}
376
378
377
379
return systemColorMode ;
0 commit comments