Skip to content

Commit c8c68d9

Browse files
authored
Implemented SystemColors.AccentColor API (#9400)
* Implemented SystemColors.AccentColor API * Addressed review comments
1 parent 1f2a4a2 commit c8c68d9

File tree

6 files changed

+631
-1
lines changed

6 files changed

+631
-1
lines changed

src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVi
5050
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Style.TargetType' changed from '[LocalizabilityAttribute(17)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.NeverLocalize)]' in the implementation.
5151
CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Style.Triggers' changed from '[DesignerSerializationVisibilityAttribute(2)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]' in the implementation.
5252
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.
53+
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.
54+
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.
55+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorBrushKey.get()' does not exist in the implementation but it does exist in the contract.
56+
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.
57+
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.
58+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark1BrushKey.get()' does not exist in the implementation but it does exist in the contract.
59+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark1Key.get()' does not exist in the implementation but it does exist in the contract.
60+
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.
61+
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.
62+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark2BrushKey.get()' does not exist in the implementation but it does exist in the contract.
63+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark2Key.get()' does not exist in the implementation but it does exist in the contract.
64+
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.
65+
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.
66+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark3BrushKey.get()' does not exist in the implementation but it does exist in the contract.
67+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorDark3Key.get()' does not exist in the implementation but it does exist in the contract.
68+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorKey.get()' does not exist in the implementation but it does exist in the contract.
69+
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.
70+
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.
71+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight1BrushKey.get()' does not exist in the implementation but it does exist in the contract.
72+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight1Key.get()' does not exist in the implementation but it does exist in the contract.
73+
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.
74+
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.
75+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight2BrushKey.get()' does not exist in the implementation but it does exist in the contract.
76+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight2Key.get()' does not exist in the implementation but it does exist in the contract.
77+
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.
78+
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.
79+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight3BrushKey.get()' does not exist in the implementation but it does exist in the contract.
80+
MembersMustExist : Member 'public System.Windows.ResourceKey System.Windows.SystemColors.AccentColorLight3Key.get()' does not exist in the implementation but it does exist in the contract.
5381
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.
5482
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.
5583
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
262290
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.
263291
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.
264292
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.
265-
Total Issues: 263
293+
Total Issues: 291

src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,7 @@
10871087
<Compile Include="System\Windows\Documents\XamlToRtfWriter.cs" />
10881088
<Compile Include="System\Windows\Documents\XPSS0ValidatingLoader.cs" />
10891089
<Compile Include="System\Windows\Documents\ZoomPercentageConverter.cs" />
1090+
<Compile Include="System\Windows\AccentColorHelper.cs" />
10901091
<Compile Include="System\Windows\DwmColorization.cs" />
10911092
<Compile Include="System\Windows\DynamicResourceExtension.cs" />
10921093
<Compile Include="System\Windows\DynamicResourceExtensionConverter.cs" />
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Windows.Media;
3+
using System.Windows.Appearance;
4+
5+
using MS.Internal;
6+
using Microsoft.Win32;
7+
using System.Runtime.InteropServices;
8+
using MS.Internal.WindowsRuntime.Windows.UI.ViewManagement;
9+
10+
11+
namespace System.Windows;
12+
13+
internal static class AccentColorHelper
14+
{
15+
16+
#region Internal Methods
17+
18+
internal static Color GetAccentColor(UISettingsRCW.UIColorType uiColorType = UISettingsRCW.UIColorType.Accent)
19+
{
20+
if (UISettings.TryGetColorValue(uiColorType, out Color color))
21+
{
22+
return color;
23+
}
24+
25+
return _defaultAccentColor;
26+
}
27+
28+
#endregion
29+
30+
#region Internal Properties
31+
32+
internal static Color SystemAccentColor
33+
{
34+
get
35+
{
36+
return GetAccentColor(UISettingsRCW.UIColorType.Accent);
37+
}
38+
}
39+
40+
private static UISettings UISettings
41+
{
42+
get
43+
{
44+
if (_uiSettings == null)
45+
{
46+
_uiSettings = new UISettings();
47+
}
48+
49+
return _uiSettings;
50+
}
51+
}
52+
53+
#endregion
54+
55+
#region Private Fields
56+
57+
private static readonly Color _defaultAccentColor = Color.FromArgb(0xff, 0x00, 0x78, 0xd4);
58+
59+
private static UISettings _uiSettings = null;
60+
61+
#endregion
62+
}

0 commit comments

Comments
 (0)