@@ -66,8 +66,6 @@ public partial class ColorPicker : Microsoft.UI.Xaml.Controls.ColorPicker
6666 private const int ColorUpdateInterval = 30 ; // Milliseconds
6767
6868 private long tokenColor ;
69- private long tokenCustomPalette ;
70- private long tokenIsColorPaletteVisible ;
7169
7270 private bool callbacksConnected = false ;
7371 private bool eventsConnected = false ;
@@ -252,23 +250,19 @@ private T GetTemplateChild<T>(string childName, bool isRequired = false)
252250 /// <param name="connected">True to connect callbacks, otherwise false.</param>
253251 private void ConnectCallbacks ( bool connected )
254252 {
255- if ( ( connected == true ) &&
256- ( this . callbacksConnected == false ) )
253+ if ( connected == true &&
254+ this . callbacksConnected == false )
257255 {
258256 // Add callbacks for dependency properties
259- this . tokenColor = this . RegisterPropertyChangedCallback ( ColorProperty , OnColorChanged ) ;
260- this . tokenCustomPalette = this . RegisterPropertyChangedCallback ( CustomPaletteProperty , OnCustomPaletteChanged ) ;
261- this . tokenIsColorPaletteVisible = this . RegisterPropertyChangedCallback ( IsColorPaletteVisibleProperty , OnIsColorPaletteVisibleChanged ) ;
257+ this . tokenColor = this . RegisterPropertyChangedCallback ( ColorProperty , OnColorChanged ) ;
262258
263259 this . callbacksConnected = true ;
264260 }
265- else if ( ( connected == false ) &&
266- ( this . callbacksConnected == true ) )
261+ else if ( connected == false &&
262+ this . callbacksConnected == true )
267263 {
268264 // Remove callbacks for dependency properties
269- this . UnregisterPropertyChangedCallback ( ColorProperty , this . tokenColor ) ;
270- this . UnregisterPropertyChangedCallback ( CustomPaletteProperty , this . tokenCustomPalette ) ;
271- this . UnregisterPropertyChangedCallback ( IsColorPaletteVisibleProperty , this . tokenIsColorPaletteVisible ) ;
265+ this . UnregisterPropertyChangedCallback ( ColorProperty , this . tokenColor ) ;
272266
273267 this . callbacksConnected = false ;
274268 }
@@ -282,8 +276,8 @@ private void ConnectCallbacks(bool connected)
282276 /// <param name="connected">True to connect event handlers, otherwise false.</param>
283277 private void ConnectEvents ( bool connected )
284278 {
285- if ( ( connected == true ) &&
286- ( this . eventsConnected == false ) )
279+ if ( connected == true &&
280+ this . eventsConnected == false )
287281 {
288282 // Add all events
289283 if ( this . ColorSpectrumControl != null ) { this . ColorSpectrumControl . ColorChanged += ColorSpectrum_ColorChanged ; }
@@ -336,8 +330,8 @@ private void ConnectEvents(bool connected)
336330
337331 this . eventsConnected = true ;
338332 }
339- else if ( ( connected == false ) &&
340- ( this . eventsConnected == true ) )
333+ else if ( connected == false &&
334+ this . eventsConnected == true )
341335 {
342336 // Remove all events
343337 if ( this . ColorSpectrumControl != null ) { this . ColorSpectrumControl . ColorChanged -= ColorSpectrum_ColorChanged ; }
@@ -1112,6 +1106,41 @@ private void ValidateSelectedPanel()
11121106 return ;
11131107 }
11141108
1109+ private void OnDependencyPropertyChanged ( object sender , DependencyPropertyChangedEventArgs args )
1110+ {
1111+ DependencyObject senderControl = sender as DependencyObject ;
1112+
1113+ /* Note: ColorProperty is defined in the base class and cannot be used here
1114+ * See the OnColorChanged callback below
1115+ */
1116+
1117+ if ( object . ReferenceEquals ( args . Property , CustomPaletteProperty ) )
1118+ {
1119+ IColorPalette palette = this . CustomPalette ;
1120+
1121+ if ( palette != null )
1122+ {
1123+ this . CustomPaletteColumnCount = palette . ColorCount ;
1124+ this . CustomPaletteColors . Clear ( ) ;
1125+
1126+ for ( int shadeIndex = 0 ; shadeIndex < palette . ShadeCount ; shadeIndex ++ )
1127+ {
1128+ for ( int colorIndex = 0 ; colorIndex < palette . ColorCount ; colorIndex ++ )
1129+ {
1130+ this . CustomPaletteColors . Add ( palette . GetColor ( colorIndex , shadeIndex ) ) ;
1131+ }
1132+ }
1133+ }
1134+ }
1135+ else if ( object . ReferenceEquals ( args . Property , IsColorPaletteVisibleProperty ) )
1136+ {
1137+ this . UpdateVisualState ( false ) ;
1138+ this . ValidateSelectedPanel ( ) ;
1139+ }
1140+
1141+ return ;
1142+ }
1143+
11151144 /***************************************************************************************
11161145 *
11171146 * Color Update Timer
@@ -1194,39 +1223,6 @@ private void OnColorChanged(DependencyObject d, DependencyProperty e)
11941223 return ;
11951224 }
11961225
1197- /// <summary>
1198- /// Callback for when the <see cref="CustomPalette"/> dependency property value changes.
1199- /// </summary>
1200- private void OnCustomPaletteChanged ( DependencyObject d , DependencyProperty e )
1201- {
1202- IColorPalette palette = this . CustomPalette ;
1203-
1204- if ( palette != null )
1205- {
1206- this . CustomPaletteColumnCount = palette . ColorCount ;
1207- this . CustomPaletteColors . Clear ( ) ;
1208-
1209- for ( int shadeIndex = 0 ; shadeIndex < palette . ShadeCount ; shadeIndex ++ )
1210- {
1211- for ( int colorIndex = 0 ; colorIndex < palette . ColorCount ; colorIndex ++ )
1212- {
1213- this . CustomPaletteColors . Add ( palette . GetColor ( colorIndex , shadeIndex ) ) ;
1214- }
1215- }
1216- }
1217-
1218- return ;
1219- }
1220-
1221- /// <summary>
1222- /// Callback for when the <see cref="IsColorPaletteVisible"/> dependency property value changes.
1223- /// </summary>
1224- private void OnIsColorPaletteVisibleChanged ( DependencyObject d , DependencyProperty e )
1225- {
1226- this . UpdateVisualState ( false ) ;
1227- return ;
1228- }
1229-
12301226 /***************************************************************************************
12311227 *
12321228 * Event Handling
0 commit comments