@@ -66,8 +66,6 @@ public partial class ColorPicker : Microsoft.UI.Xaml.Controls.ColorPicker
66
66
private const int ColorUpdateInterval = 30 ; // Milliseconds
67
67
68
68
private long tokenColor ;
69
- private long tokenCustomPalette ;
70
- private long tokenIsColorPaletteVisible ;
71
69
72
70
private bool callbacksConnected = false ;
73
71
private bool eventsConnected = false ;
@@ -252,23 +250,19 @@ private T GetTemplateChild<T>(string childName, bool isRequired = false)
252
250
/// <param name="connected">True to connect callbacks, otherwise false.</param>
253
251
private void ConnectCallbacks ( bool connected )
254
252
{
255
- if ( ( connected == true ) &&
256
- ( this . callbacksConnected == false ) )
253
+ if ( connected == true &&
254
+ this . callbacksConnected == false )
257
255
{
258
256
// 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 ) ;
262
258
263
259
this . callbacksConnected = true ;
264
260
}
265
- else if ( ( connected == false ) &&
266
- ( this . callbacksConnected == true ) )
261
+ else if ( connected == false &&
262
+ this . callbacksConnected == true )
267
263
{
268
264
// 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 ) ;
272
266
273
267
this . callbacksConnected = false ;
274
268
}
@@ -282,8 +276,8 @@ private void ConnectCallbacks(bool connected)
282
276
/// <param name="connected">True to connect event handlers, otherwise false.</param>
283
277
private void ConnectEvents ( bool connected )
284
278
{
285
- if ( ( connected == true ) &&
286
- ( this . eventsConnected == false ) )
279
+ if ( connected == true &&
280
+ this . eventsConnected == false )
287
281
{
288
282
// Add all events
289
283
if ( this . ColorSpectrumControl != null ) { this . ColorSpectrumControl . ColorChanged += ColorSpectrum_ColorChanged ; }
@@ -336,8 +330,8 @@ private void ConnectEvents(bool connected)
336
330
337
331
this . eventsConnected = true ;
338
332
}
339
- else if ( ( connected == false ) &&
340
- ( this . eventsConnected == true ) )
333
+ else if ( connected == false &&
334
+ this . eventsConnected == true )
341
335
{
342
336
// Remove all events
343
337
if ( this . ColorSpectrumControl != null ) { this . ColorSpectrumControl . ColorChanged -= ColorSpectrum_ColorChanged ; }
@@ -1112,6 +1106,41 @@ private void ValidateSelectedPanel()
1112
1106
return ;
1113
1107
}
1114
1108
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
+
1115
1144
/***************************************************************************************
1116
1145
*
1117
1146
* Color Update Timer
@@ -1194,39 +1223,6 @@ private void OnColorChanged(DependencyObject d, DependencyProperty e)
1194
1223
return ;
1195
1224
}
1196
1225
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
-
1230
1226
/***************************************************************************************
1231
1227
*
1232
1228
* Event Handling
0 commit comments