@@ -9,7 +9,11 @@ namespace CommunityToolkit.WinUI.Helpers;
99
1010public partial class AccentAnalyzer
1111{
12- private UIElement ? _source ;
12+ /// <summary>
13+ /// Gets the <see cref="DependencyProperty"/> for the <see cref="Source"/> property.
14+ /// </summary>
15+ public static readonly DependencyProperty SourceProperty =
16+ DependencyProperty . Register ( nameof ( Source ) , typeof ( UIElement ) , typeof ( AccentAnalyzer ) , new PropertyMetadata ( null , OnSourceChanged ) ) ;
1317
1418 /// <summary>
1519 /// Gets the <see cref="DependencyProperty"/> for the <see cref="PrimaryAccentColor"/> property.
@@ -52,6 +56,15 @@ public partial class AccentAnalyzer
5256 /// </summary>
5357 public event EventHandler ? AccentsUpdated ;
5458
59+ /// <summary>
60+ /// Gets or sets the <see cref="UIElement"/> source for accent color analysis.
61+ /// </summary>
62+ public UIElement ? Source
63+ {
64+ get => ( UIElement ) GetValue ( SourceProperty ) ;
65+ set => SetValue ( SourceProperty , value ) ;
66+ }
67+
5568 /// <summary>
5669 /// Gets the primary accent color as extracted from the <see cref="Source"/>.
5770 /// </summary>
@@ -111,13 +124,16 @@ public Color DominantColor
111124 get => ( Color ) GetValue ( DominantColorProperty ) ;
112125 protected set => SetValue ( DominantColorProperty , value ) ;
113126 }
114-
127+
115128 /// <summary>
116129 /// Gets the "colorfulness" of the <see cref="Source"/>.
117130 /// </summary>
118131 /// <remarks>
119132 /// Colorfulness is defined by David Hasler and Sabine Susstrunk's paper on measuring colorfulness
120- /// <seealso href="https://infoscience.epfl.ch/server/api/core/bitstreams/77f5adab-e825-4995-92db-c9ff4cd8bf5a/content"/>
133+ /// <seealso href="https://infoscience.epfl.ch/server/api/core/bitstreams/77f5adab-e825-4995-92db-c9ff4cd8bf5a/content"/>.
134+ ///
135+ /// An image with colors of high saturation and value will have a high colorfulness (around 1),
136+ /// meanwhile images that are mostly gray or white will have a low colorfulness (around 0).
121137 /// </remarks>
122138 public float Colorfulness
123139 {
@@ -135,18 +151,11 @@ public float Colorfulness
135151 /// </summary>
136152 public ICommand AccentUpdateCommand { get ; }
137153
138- /// <summary>
139- /// Gets or sets the <see cref="UIElement"/>
140- /// </summary>
141- public UIElement ? Source
154+ private static void OnSourceChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
142155 {
143- get => _source ;
144- set => SetSource ( value ) ;
145- }
156+ if ( d is not AccentAnalyzer analyzer )
157+ return ;
146158
147- private void SetSource ( UIElement ? source )
148- {
149- _source = source ;
150- _ = UpdateAccentAsync ( ) ;
159+ _ = analyzer . UpdateAccentAsync ( ) ;
151160 }
152161}
0 commit comments