From 40499a88b8aceffe1541302781beadcee19ca67f Mon Sep 17 00:00:00 2001 From: dipeshmsft Date: Mon, 15 Jul 2024 10:31:24 +0530 Subject: [PATCH 1/2] Implemented SystemColors.AccentColor API --- .../PresentationFramework-ref.baseline.txt | 30 +- .../PresentationFramework.csproj | 1 + .../System/Windows/AccentColorHelper.cs | 64 +++ .../System/Windows/SystemColors.cs | 434 ++++++++++++++++++ .../System/Windows/SystemResourceKey.cs | 99 ++++ .../System/Windows/SystemResources.cs | 6 + 6 files changed, 633 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/AccentColorHelper.cs diff --git a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt index 8c623516c79..db924382512 100644 --- a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt +++ b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt @@ -50,6 +50,34 @@ CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVi CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Style.TargetType' changed from '[LocalizabilityAttribute(17)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.NeverLocalize)]' in the implementation. CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Style.Triggers' changed from '[DesignerSerializationVisibilityAttribute(2)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]' in the implementation. CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'System.Windows.StyleTypedPropertyAttribute' changed from '[AttributeUsageAttribute(4, AllowMultiple=true)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true)]' in the implementation. +MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColor.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorBrush.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorBrushKey.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorDark1.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorDark1Brush.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark1BrushKey.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark1Key.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorDark2.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorDark2Brush.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark2BrushKey.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark2Key.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorDark3.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorDark3Brush.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark3BrushKey.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark3Key.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorKey.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorLight1.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorLight1Brush.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight1BrushKey.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight1Key.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorLight2.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorLight2Brush.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight2BrushKey.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight2Key.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.Color System.Windows.SystemColors.AccentColorLight3.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.Media.SolidColorBrush System.Windows.SystemColors.AccentColorLight3Brush.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight3BrushKey.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight3Key.get()' does not exist in the implementation but it does exist in the contract. CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'System.Windows.TemplatePartAttribute' changed from '[AttributeUsageAttribute(4, AllowMultiple=true)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true)]' in the implementation. CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'System.Windows.TemplateVisualStateAttribute' changed from '[AttributeUsageAttribute(4, AllowMultiple=true)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true)]' in the implementation. CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'System.Windows.ThemeInfoAttribute' changed from '[AttributeUsageAttribute(1)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Assembly)]' in the implementation. @@ -262,4 +290,4 @@ CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVi CannotChangeAttribute : Attribute 'System.Windows.Markup.DesignerSerializationOptionsAttribute' on 'System.Windows.Markup.XmlAttributeProperties.GetXmlSpace(System.Windows.DependencyObject)' changed from '[DesignerSerializationOptionsAttribute(1)]' in the contract to '[DesignerSerializationOptionsAttribute(DesignerSerializationOptions.SerializeAsAttribute)]' in the implementation. CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Media.Animation.Storyboard.GetTarget(System.Windows.DependencyObject)' changed from '[DesignerSerializationVisibilityAttribute(0)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]' in the implementation. CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Shapes.Shape' changed from '[LocalizabilityAttribute(0, Readability=0)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)]' in the implementation. -Total Issues: 263 +Total Issues: 291 diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj index ecb8e8dd265..08dff73c8e8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj @@ -1087,6 +1087,7 @@ + diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/AccentColorHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/AccentColorHelper.cs new file mode 100644 index 00000000000..ee65740de02 --- /dev/null +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/AccentColorHelper.cs @@ -0,0 +1,64 @@ +using System; +using System.Windows.Media; +using System.Windows.Appearance; + +using MS.Internal; +using Microsoft.Win32; +using System.Runtime.InteropServices; +using MS.Internal.WindowsRuntime.Windows.UI.ViewManagement; + + +namespace System.Windows; + +internal static class AccentColorHelper +{ + + #region Internal Methods + + internal static Color GetAccentColor(UISettingsRCW.UIColorType uiColorType = UISettingsRCW.UIColorType.Accent) + { + Color color = _defaultAccentColor; + + if (_UISettings.TryGetColorValue(uiColorType, out color)) + { + return color; + } + + return color; + } + + #endregion + + #region Internal Properties + + internal static Color SystemAccentColor + { + get + { + return GetAccentColor(UISettingsRCW.UIColorType.Accent); + } + } + + internal static UISettings _UISettings + { + get + { + if (_uiSettings == null) + { + _uiSettings = new UISettings(); + } + + return _uiSettings; + } + } + + #endregion + + #region Private Fields + + private static Color _defaultAccentColor = Color.FromArgb(0xff, 0x00, 0x78, 0xd4); + + private static UISettings _uiSettings = null; + + #endregion +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemColors.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemColors.cs index a6afebd3126..a2b8c5a8b0a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemColors.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemColors.cs @@ -7,6 +7,7 @@ using System.Windows.Media; using Microsoft.Win32; using MS.Win32; +using UISettingsRCW = MS.Internal.WindowsRuntime.Windows.UI.ViewManagement.UISettingsRCW; namespace System.Windows { @@ -347,6 +348,62 @@ public static Color WindowTextColor } } + public static Color AccentColor + { + get + { + return GetAccentColor(CacheSlot.AccentColor); + } + } + + public static Color AccentColorLight1 + { + get + { + return GetAccentColor(CacheSlot.AccentColorLight1); + } + } + + public static Color AccentColorLight2 + { + get + { + return GetAccentColor(CacheSlot.AccentColorLight2); + } + } + + public static Color AccentColorLight3 + { + get + { + return GetAccentColor(CacheSlot.AccentColorLight3); + } + } + + public static Color AccentColorDark1 + { + get + { + return GetAccentColor(CacheSlot.AccentColorDark1); + } + } + + public static Color AccentColorDark2 + { + get + { + return GetAccentColor(CacheSlot.AccentColorDark2); + } + } + + public static Color AccentColorDark3 + { + get + { + return GetAccentColor(CacheSlot.AccentColorDark3); + } + } + #endregion [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] @@ -837,6 +894,97 @@ public static ResourceKey WindowTextColorKey } } + public static ResourceKey AccentColorKey + { + get + { + if (_cacheAccentColor == null) + { + _cacheAccentColor = CreateInstance(SystemResourceKeyID.AccentColor); + } + + return _cacheAccentColor; + } + } + + public static ResourceKey AccentColorLight1Key + { + get + { + if (_cacheAccentColorLight1 == null) + { + _cacheAccentColorLight1 = CreateInstance(SystemResourceKeyID.AccentColorLight1); + } + + return _cacheAccentColorLight1; + } + } + + public static ResourceKey AccentColorLight2Key + { + get + { + if (_cacheAccentColorLight2 == null) + { + _cacheAccentColorLight2 = CreateInstance(SystemResourceKeyID.AccentColorLight2); + } + + return _cacheAccentColorLight2; + } + } + + public static ResourceKey AccentColorLight3Key + { + get + { + if (_cacheAccentColorLight3 == null) + { + _cacheAccentColorLight3 = CreateInstance(SystemResourceKeyID.AccentColorLight3); + } + + return _cacheAccentColorLight3; + } + } + + public static ResourceKey AccentColorDark1Key + { + get + { + if (_cacheAccentColorDark1 == null) + { + _cacheAccentColorDark1 = CreateInstance(SystemResourceKeyID.AccentColorDark1); + } + + return _cacheAccentColorDark1; + } + } + + public static ResourceKey AccentColorDark2Key + { + get + { + if (_cacheAccentColorDark2 == null) + { + _cacheAccentColorDark2 = CreateInstance(SystemResourceKeyID.AccentColorDark2); + } + + return _cacheAccentColorDark2; + } + } + + public static ResourceKey AccentColorDark3Key + { + get + { + if (_cacheAccentColorDark3 == null) + { + _cacheAccentColorDark3 = CreateInstance(SystemResourceKeyID.AccentColorDark3); + } + + return _cacheAccentColorDark3; + } + } + #endregion #region Brushes @@ -1213,6 +1361,111 @@ public static SolidColorBrush InactiveSelectionHighlightTextBrush } } + public static SolidColorBrush AccentColorBrush + { + get + { + if (SystemParameters.HighContrast) + { + return SystemColors.HighlightTextBrush; + } + else + { + return MakeAccentBrush(CacheSlot.AccentColor); + } + } + } + + public static SolidColorBrush AccentColorLight1Brush + { + get + { + if (SystemParameters.HighContrast) + { + return SystemColors.HighlightTextBrush; + } + else + { + return MakeAccentBrush(CacheSlot.AccentColorLight1); + } + } + } + + public static SolidColorBrush AccentColorLight2Brush + { + get + { + if (SystemParameters.HighContrast) + { + return SystemColors.HighlightTextBrush; + } + else + { + return MakeAccentBrush(CacheSlot.AccentColorLight2); + } + } + } + + public static SolidColorBrush AccentColorLight3Brush + { + get + { + if (SystemParameters.HighContrast) + { + return SystemColors.HighlightTextBrush; + } + else + { + return MakeAccentBrush(CacheSlot.AccentColorLight3); + } + } + } + + public static SolidColorBrush AccentColorDark1Brush + { + get + { + if (SystemParameters.HighContrast) + { + return SystemColors.HighlightTextBrush; + } + else + { + return MakeAccentBrush(CacheSlot.AccentColorDark1); + } + } + } + + public static SolidColorBrush AccentColorDark2Brush + { + get + { + if (SystemParameters.HighContrast) + { + return SystemColors.HighlightTextBrush; + } + else + { + return MakeAccentBrush(CacheSlot.AccentColorDark2); + } + } + } + + public static SolidColorBrush AccentColorDark3Brush + { + get + { + if (SystemParameters.HighContrast) + { + return SystemColors.HighlightTextBrush; + } + else + { + return MakeAccentBrush(CacheSlot.AccentColorDark3); + } + } + } + #endregion #region Brush Keys @@ -1743,6 +1996,97 @@ public static ResourceKey InactiveSelectionHighlightTextBrushKey } } + public static ResourceKey AccentColorBrushKey + { + get + { + if(_cacheAccentColorBrush == null) + { + _cacheAccentColorBrush = CreateInstance(SystemResourceKeyID.AccentColorBrush); + } + + return _cacheAccentColorBrush; + } + } + + public static ResourceKey AccentColorLight1BrushKey + { + get + { + if(_cacheAccentColorLight1Brush == null) + { + _cacheAccentColorLight1Brush = CreateInstance(SystemResourceKeyID.AccentColorLight1Brush); + } + + return _cacheAccentColorLight1Brush; + } + } + + public static ResourceKey AccentColorLight2BrushKey + { + get + { + if(_cacheAccentColorLight2Brush == null) + { + _cacheAccentColorLight2Brush = CreateInstance(SystemResourceKeyID.AccentColorLight2Brush); + } + + return _cacheAccentColorLight2Brush; + } + } + + public static ResourceKey AccentColorLight3BrushKey + { + get + { + if(_cacheAccentColorLight3Brush == null) + { + _cacheAccentColorLight3Brush = CreateInstance(SystemResourceKeyID.AccentColorLight3Brush); + } + + return _cacheAccentColorLight3Brush; + } + } + + public static ResourceKey AccentColorDark1BrushKey + { + get + { + if(_cacheAccentColorDark1Brush == null) + { + _cacheAccentColorDark1Brush = CreateInstance(SystemResourceKeyID.AccentColorDark1Brush); + } + + return _cacheAccentColorDark1Brush; + } + } + + public static ResourceKey AccentColorDark2BrushKey + { + get + { + if(_cacheAccentColorDark2Brush == null) + { + _cacheAccentColorDark2Brush = CreateInstance(SystemResourceKeyID.AccentColorDark2Brush); + } + + return _cacheAccentColorDark2Brush; + } + } + + public static ResourceKey AccentColorDark3BrushKey + { + get + { + if(_cacheAccentColorDark3Brush == null) + { + _cacheAccentColorDark3Brush = CreateInstance(SystemResourceKeyID.AccentColorDark3Brush); + } + + return _cacheAccentColorDark3Brush; + } + } + #endregion #region Implementation @@ -1808,6 +2152,53 @@ private static Color GetSystemColor(CacheSlot slot) return color; } + private static Color GetAccentColor(CacheSlot slot) + { + Color color; + + lock (_colorCacheValid) + { + while(!_colorCacheValid[(int)slot]) + { + _colorCacheValid[(int)slot] = true; + + switch(slot) + { + case CacheSlot.AccentColor: + color = AccentColorHelper.GetAccentColor(UISettingsRCW.UIColorType.Accent); + break; + case CacheSlot.AccentColorLight1: + color = AccentColorHelper.GetAccentColor(UISettingsRCW.UIColorType.AccentLight1); + break; + case CacheSlot.AccentColorLight2: + color = AccentColorHelper.GetAccentColor(UISettingsRCW.UIColorType.AccentLight2); + break; + case CacheSlot.AccentColorLight3: + color = AccentColorHelper.GetAccentColor(UISettingsRCW.UIColorType.AccentLight3); + break; + case CacheSlot.AccentColorDark1: + color = AccentColorHelper.GetAccentColor(UISettingsRCW.UIColorType.AccentDark1); + break; + case CacheSlot.AccentColorDark2: + color = AccentColorHelper.GetAccentColor(UISettingsRCW.UIColorType.AccentDark2); + break; + case CacheSlot.AccentColorDark3: + color = AccentColorHelper.GetAccentColor(UISettingsRCW.UIColorType.AccentDark3); + break; + default: + color = Colors.Transparent; + break; + } + + _colorCache[(int)slot] = color; + } + + color = _colorCache[(int)slot]; + } + + return color; + } + private static SolidColorBrush MakeBrush(CacheSlot slot) { SolidColorBrush brush; @@ -1831,6 +2222,28 @@ private static SolidColorBrush MakeBrush(CacheSlot slot) return brush; } + private static SolidColorBrush MakeAccentBrush(CacheSlot slot) + { + SolidColorBrush brush; + + lock(_brushCacheValid) + { + while(!_brushCacheValid[(int)slot]) + { + _brushCacheValid[(int)slot] = true; + + brush = new SolidColorBrush(GetAccentColor(slot)); + brush.Freeze(); + + _brushCache[(int)slot] = brush; + } + + brush = _brushCache[(int)slot]; + } + + return brush; + } + private static int SlotToFlag(CacheSlot slot) { // FxCop: Hashtable would be overkill, using switch instead @@ -1934,6 +2347,13 @@ private enum CacheSlot : int Window, WindowFrame, WindowText, + AccentColor, + AccentColorLight1, + AccentColorLight2, + AccentColorLight3, + AccentColorDark1, + AccentColorDark2, + AccentColorDark3, NumSlots } @@ -1975,6 +2395,13 @@ private enum CacheSlot : int private static SystemResourceKey _cacheWindowTextBrush; private static SystemResourceKey _cacheInactiveSelectionHighlightBrush; private static SystemResourceKey _cacheInactiveSelectionHighlightTextBrush; + private static SystemResourceKey _cacheAccentColorBrush; + private static SystemResourceKey _cacheAccentColorLight1Brush; + private static SystemResourceKey _cacheAccentColorLight2Brush; + private static SystemResourceKey _cacheAccentColorLight3Brush; + private static SystemResourceKey _cacheAccentColorDark1Brush; + private static SystemResourceKey _cacheAccentColorDark2Brush; + private static SystemResourceKey _cacheAccentColorDark3Brush; private static SystemResourceKey _cacheActiveBorderColor; private static SystemResourceKey _cacheActiveCaptionColor; private static SystemResourceKey _cacheActiveCaptionTextColor; @@ -2005,6 +2432,13 @@ private enum CacheSlot : int private static SystemResourceKey _cacheWindowColor; private static SystemResourceKey _cacheWindowFrameColor; private static SystemResourceKey _cacheWindowTextColor; + private static SystemResourceKey _cacheAccentColor; + private static SystemResourceKey _cacheAccentColorLight1; + private static SystemResourceKey _cacheAccentColorLight2; + private static SystemResourceKey _cacheAccentColorLight3; + private static SystemResourceKey _cacheAccentColorDark1; + private static SystemResourceKey _cacheAccentColorDark2; + private static SystemResourceKey _cacheAccentColorDark3; #endregion } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResourceKey.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResourceKey.cs index afaaf209374..5b8d4192ea7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResourceKey.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResourceKey.cs @@ -282,6 +282,21 @@ internal enum SystemResourceKeyID InactiveSelectionHighlightBrush, InactiveSelectionHighlightTextBrush, + AccentColor, + AccentColorLight1, + AccentColorLight2, + AccentColorLight3, + AccentColorDark1, + AccentColorDark2, + AccentColorDark3, + AccentColorBrush, + AccentColorLight1Brush, + AccentColorLight2Brush, + AccentColorLight3Brush, + AccentColorDark1Brush, + AccentColorDark2Brush, + AccentColorDark3Brush, + InternalSystemColorsExtendedEnd } @@ -535,6 +550,27 @@ internal object Resource case SystemResourceKeyID.InactiveSelectionHighlightTextBrush: return SystemColors.InactiveSelectionHighlightTextBrush; + case SystemResourceKeyID.AccentColorBrush: + return SystemColors.AccentColorBrush; + + case SystemResourceKeyID.AccentColorLight1Brush: + return SystemColors.AccentColorLight1Brush; + + case SystemResourceKeyID.AccentColorLight2Brush: + return SystemColors.AccentColorLight2Brush; + + case SystemResourceKeyID.AccentColorLight3Brush: + return SystemColors.AccentColorLight3Brush; + + case SystemResourceKeyID.AccentColorDark1Brush: + return SystemColors.AccentColorDark1Brush; + + case SystemResourceKeyID.AccentColorDark2Brush: + return SystemColors.AccentColorDark2Brush; + + case SystemResourceKeyID.AccentColorDark3Brush: + return SystemColors.AccentColorDark3Brush; + case SystemResourceKeyID.ActiveBorderColor: return SystemColors.ActiveBorderColor; @@ -625,6 +661,27 @@ internal object Resource case SystemResourceKeyID.WindowTextColor: return SystemColors.WindowTextColor; + case SystemResourceKeyID.AccentColor: + return SystemColors.AccentColor; + + case SystemResourceKeyID.AccentColorLight1: + return SystemColors.AccentColorLight1; + + case SystemResourceKeyID.AccentColorLight2: + return SystemColors.AccentColorLight2; + + case SystemResourceKeyID.AccentColorLight3: + return SystemColors.AccentColorLight3; + + case SystemResourceKeyID.AccentColorDark1: + return SystemColors.AccentColorDark1; + + case SystemResourceKeyID.AccentColorDark2: + return SystemColors.AccentColorDark2; + + case SystemResourceKeyID.AccentColorDark3: + return SystemColors.AccentColorDark3; + case SystemResourceKeyID.ThinHorizontalBorderHeight: return SystemParameters.ThinHorizontalBorderHeight; @@ -1177,6 +1234,27 @@ internal static ResourceKey GetResourceKey(short id) case (short)SystemResourceKeyID.InactiveSelectionHighlightTextBrush: return SystemColors.InactiveSelectionHighlightTextBrushKey; + case (short)SystemResourceKeyID.AccentColorBrush: + return SystemColors.AccentColorBrushKey; + + case (short)SystemResourceKeyID.AccentColorLight1Brush: + return SystemColors.AccentColorLight1BrushKey; + + case (short)SystemResourceKeyID.AccentColorLight2Brush: + return SystemColors.AccentColorLight2BrushKey; + + case (short)SystemResourceKeyID.AccentColorLight3Brush: + return SystemColors.AccentColorLight3BrushKey; + + case (short)SystemResourceKeyID.AccentColorDark1Brush: + return SystemColors.AccentColorDark1BrushKey; + + case (short)SystemResourceKeyID.AccentColorDark2Brush: + return SystemColors.AccentColorDark2BrushKey; + + case (short)SystemResourceKeyID.AccentColorDark3Brush: + return SystemColors.AccentColorDark3BrushKey; + case (short)SystemResourceKeyID.ActiveBorderColor: return SystemColors.ActiveBorderColorKey; @@ -1267,6 +1345,27 @@ internal static ResourceKey GetResourceKey(short id) case (short)SystemResourceKeyID.WindowTextColor: return SystemColors.WindowTextColorKey; + case (short)SystemResourceKeyID.AccentColor: + return SystemColors.AccentColorKey; + + case (short)SystemResourceKeyID.AccentColorLight1: + return SystemColors.AccentColorLight1Key; + + case (short)SystemResourceKeyID.AccentColorLight2: + return SystemColors.AccentColorLight2Key; + + case (short)SystemResourceKeyID.AccentColorLight3: + return SystemColors.AccentColorLight3Key; + + case (short)SystemResourceKeyID.AccentColorDark1: + return SystemColors.AccentColorDark1Key; + + case (short)SystemResourceKeyID.AccentColorDark2: + return SystemColors.AccentColorDark2Key; + + case (short)SystemResourceKeyID.AccentColorDark3: + return SystemColors.AccentColorDark3Key; + case (short)SystemResourceKeyID.ThinHorizontalBorderHeight: return SystemParameters.ThinHorizontalBorderHeightKey; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs index 4a6622b9d01..4e181a12101 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs @@ -1434,6 +1434,12 @@ private static IntPtr SystemThemeFilterMessage(IntPtr hwnd, int msg, IntPtr wPar case WindowMessage.WM_DWMCOLORIZATIONCOLORCHANGED: SystemParameters.InvalidateWindowGlassColorizationProperties(); + + if(SystemColors.InvalidateCache()) + { + OnSystemValueChanged(); + InvalidateResources(true); + } break; } From 19385c34cc514636915c9266a3fd6240479ec2e0 Mon Sep 17 00:00:00 2001 From: dipeshmsft Date: Wed, 17 Jul 2024 11:41:21 +0530 Subject: [PATCH 2/2] Addressed review comments --- .../System/Windows/AccentColorHelper.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/AccentColorHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/AccentColorHelper.cs index ee65740de02..abf767a129b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/AccentColorHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/AccentColorHelper.cs @@ -17,14 +17,12 @@ internal static class AccentColorHelper internal static Color GetAccentColor(UISettingsRCW.UIColorType uiColorType = UISettingsRCW.UIColorType.Accent) { - Color color = _defaultAccentColor; - - if (_UISettings.TryGetColorValue(uiColorType, out color)) + if (UISettings.TryGetColorValue(uiColorType, out Color color)) { return color; } - return color; + return _defaultAccentColor; } #endregion @@ -39,7 +37,7 @@ internal static Color SystemAccentColor } } - internal static UISettings _UISettings + private static UISettings UISettings { get { @@ -56,7 +54,7 @@ internal static UISettings _UISettings #region Private Fields - private static Color _defaultAccentColor = Color.FromArgb(0xff, 0x00, 0x78, 0xd4); + private static readonly Color _defaultAccentColor = Color.FromArgb(0xff, 0x00, 0x78, 0xd4); private static UISettings _uiSettings = null;