@@ -427,6 +427,11 @@ internal static class KnownColorTable
427427 KnownColorKindWeb , // RebeccaPurple
428428 ] ;
429429
430+ // These values were based on manual investigation of dark mode themes in the
431+ // Win32 Common Controls and WinUI. There aren't direct mappings published by
432+ // Windows, these may change slightly when this feature is finalized to make
433+ // sure we have the best experience in hybrid dark mode scenarios (mixing
434+ // WPF, WinForms, and WinUI).
430435 private static ReadOnlySpan < uint > AlternateSystemColors =>
431436 [
432437 0 , // To align with KnownColor.ActiveBorder = 1
@@ -494,18 +499,24 @@ public static uint KnownColorToArgb(KnownColor color)
494499 : ColorValueTable [ ( int ) color ] ;
495500 }
496501
502+ private static uint GetAlternateSystemColorArgb ( KnownColor color )
503+ {
504+ // Shift the original (split) index to fit the alternate color map.
505+ int index = color <= KnownColor . WindowText
506+ ? ( int ) color
507+ : ( int ) color - ( int ) KnownColor . ButtonFace + ( int ) KnownColor . WindowText + 1 ;
508+
509+ return AlternateSystemColors [ index ] ;
510+ }
511+
497512#if FEATURE_WINDOWS_SYSTEM_COLORS
498513 public static uint GetSystemColorArgb ( KnownColor color )
499514 {
500515 Debug . Assert ( Color . IsKnownColorSystem ( color ) ) ;
501516
502- if ( ! SystemColors . s_useAlternativeColorSet || HighContrastEnabled ( ) )
503- {
504- return ColorTranslator . COLORREFToARGB ( Interop . User32 . GetSysColor ( ( byte ) ColorValueTable [ ( int ) color ] ) ) ;
505- }
506-
507- int index = color <= KnownColor . WindowText ? ( int ) color : ( int ) color - ( int ) KnownColor . ButtonFace + ( int ) KnownColor . WindowText + 1 ;
508- return AlternateSystemColors [ index ] ;
517+ return ! SystemColors . s_useAlternativeColorSet || HighContrastEnabled ( )
518+ ? ColorTranslator . COLORREFToARGB ( Interop . User32 . GetSysColor ( ( byte ) ColorValueTable [ ( int ) color ] ) )
519+ : GetAlternateSystemColorArgb ( color ) ;
509520 }
510521
511522 private static unsafe bool HighContrastEnabled ( )
@@ -529,13 +540,9 @@ public static uint GetSystemColorArgb(KnownColor color)
529540 {
530541 Debug . Assert ( Color . IsKnownColorSystem ( color ) ) ;
531542
532- if ( ! SystemColors . s_useAlternativeColorSet )
533- {
534- return ColorValueTable [ ( int ) color ] ;
535- }
536-
537- int index = color <= KnownColor . WindowText ? ( int ) color : ( int ) color - ( int ) KnownColor . ButtonFace + ( int ) KnownColor . WindowText + 1 ;
538- return AlternateSystemColors [ index ] ;
543+ return ( ! SystemColors . s_useAlternativeColorSet )
544+ ? ColorValueTable [ ( int ) color ]
545+ : GetAlternateSystemColorArgb ( color ) ;
539546 }
540547#endif
541548 }
0 commit comments