@@ -16,7 +16,8 @@ namespace Monitorian.Core.Views
1616 /// </remarks>
1717 public static class UISettings
1818 {
19- private static Windows . UI . ViewManagement . UISettings _uiSettings ;
19+ // UISettings.ColorValuesChanged is not supported in desktop apps.
20+ // https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-supported-api#unsupported-members
2021
2122 /// <summary>
2223 /// Gets the system accent color.
@@ -42,56 +43,12 @@ public static class UISettings
4243 /// <returns></returns>
4344 public static Color GetBackgroundColor ( ) => GetUIColor ( Windows . UI . ViewManagement . UIColorType . Background ) ;
4445
46+ private static Windows . UI . ViewManagement . UISettings _uiSettings ;
47+
4548 private static Color GetUIColor ( Windows . UI . ViewManagement . UIColorType colorType )
4649 {
47- var value = ( _uiSettings ?? new Windows . UI . ViewManagement . UISettings ( ) ) . GetColorValue ( colorType ) ;
50+ var value = ( _uiSettings ??= new Windows . UI . ViewManagement . UISettings ( ) ) . GetColorValue ( colorType ) ;
4851 return Color . FromArgb ( value . A , value . R , value . G , value . B ) ;
4952 }
50-
51- private static readonly object _lock = new ( ) ;
52-
53- /// <summary>
54- /// Occurs when colors have changed.
55- /// </summary>
56- /// <remarks>
57- /// UISettings.ColorValuesChanged event seems not to fire when this assembly is packaged.
58- /// </remarks>
59- public static event EventHandler ColorsChanged
60- {
61- add
62- {
63- lock ( _lock )
64- {
65- _colorsChanged += value ;
66-
67- if ( _uiSettings is null )
68- {
69- _uiSettings = new Windows . UI . ViewManagement . UISettings ( ) ;
70- _uiSettings . ColorValuesChanged += OnColorValuesChanged ;
71- }
72- }
73- }
74- remove
75- {
76- lock ( _lock )
77- {
78- _colorsChanged -= value ;
79- if ( _colorsChanged is not null )
80- return ;
81-
82- if ( _uiSettings is not null )
83- {
84- _uiSettings . ColorValuesChanged -= OnColorValuesChanged ;
85- _uiSettings = null ;
86- }
87- }
88- }
89- }
90- private static event EventHandler _colorsChanged ;
91-
92- private static void OnColorValuesChanged ( Windows . UI . ViewManagement . UISettings sender , object args )
93- {
94- _colorsChanged ? . Invoke ( sender , EventArgs . Empty ) ;
95- }
9653 }
9754}
0 commit comments