@@ -46,6 +46,7 @@ namespace CommunityToolkit.WinUI.Controls;
4646[ TemplatePart ( Name = nameof ( ColorPicker . ColorSpectrumControl ) , Type = typeof ( ColorSpectrum ) ) ]
4747[ TemplatePart ( Name = nameof ( ColorPicker . ColorSpectrumAlphaSlider ) , Type = typeof ( ColorPickerSlider ) ) ]
4848[ TemplatePart ( Name = nameof ( ColorPicker . ColorSpectrumThirdDimensionSlider ) , Type = typeof ( ColorPickerSlider ) ) ]
49+ [ TemplatePart ( Name = nameof ( ColorPicker . PaletteItemGridView ) , Type = typeof ( GridView ) ) ]
4950[ TemplatePart ( Name = nameof ( ColorPicker . HexInputTextBox ) , Type = typeof ( TextBox ) ) ]
5051[ TemplatePart ( Name = nameof ( ColorPicker . ColorModeComboBox ) , Type = typeof ( ComboBox ) ) ]
5152
@@ -81,6 +82,7 @@ public partial class ColorPicker : Microsoft.UI.Xaml.Controls.ColorPicker
8182 private ColorSpectrum ColorSpectrumControl ;
8283 private ColorPickerSlider ColorSpectrumAlphaSlider ;
8384 private ColorPickerSlider ColorSpectrumThirdDimensionSlider ;
85+ private GridView PaletteItemGridView ;
8486 private TextBox HexInputTextBox ;
8587 private ComboBox ColorModeComboBox ;
8688
@@ -186,6 +188,8 @@ protected override void OnApplyTemplate()
186188 this . ColorSpectrumAlphaSlider = ( ColorPickerSlider ) this . GetTemplateChild ( nameof ( ColorSpectrumAlphaSlider ) ) ;
187189 this . ColorSpectrumThirdDimensionSlider = ( ColorPickerSlider ) this . GetTemplateChild ( nameof ( ColorSpectrumThirdDimensionSlider ) ) ;
188190
191+ this . PaletteItemGridView = ( GridView ) GetTemplateChild ( nameof ( PaletteItemGridView ) ) ;
192+
189193 this . HexInputTextBox = ( TextBox ) this . GetTemplateChild ( nameof ( HexInputTextBox ) ) ;
190194 this . ColorModeComboBox = ( ComboBox ) this . GetTemplateChild ( nameof ( ColorModeComboBox ) ) ;
191195
@@ -263,6 +267,9 @@ private void ConnectEvents(bool connected)
263267
264268 if ( this . ColorSpectrumControl != null ) { this . ColorSpectrumControl . ColorChanged += ColorSpectrum_ColorChanged ; }
265269 if ( this . ColorSpectrumControl != null ) { this . ColorSpectrumControl . GotFocus += ColorSpectrum_GotFocus ; }
270+
271+ if ( this . PaletteItemGridView != null ) { this . PaletteItemGridView . SelectionChanged += this . PaletteItemGridView_SelectionChanged ; }
272+
266273 if ( this . HexInputTextBox != null ) { this . HexInputTextBox . KeyDown += HexInputTextBox_KeyDown ; }
267274 if ( this . HexInputTextBox != null ) { this . HexInputTextBox . LostFocus += HexInputTextBox_LostFocus ; }
268275 if ( this . ColorModeComboBox != null ) { this . ColorModeComboBox . SelectionChanged += ColorModeComboBox_SelectionChanged ; }
@@ -309,6 +316,9 @@ private void ConnectEvents(bool connected)
309316
310317 if ( this . ColorSpectrumControl != null ) { this . ColorSpectrumControl . ColorChanged -= ColorSpectrum_ColorChanged ; }
311318 if ( this . ColorSpectrumControl != null ) { this . ColorSpectrumControl . GotFocus -= ColorSpectrum_GotFocus ; }
319+
320+ if ( this . PaletteItemGridView != null ) { this . PaletteItemGridView . SelectionChanged -= this . PaletteItemGridView_SelectionChanged ; }
321+
312322 if ( this . HexInputTextBox != null ) { this . HexInputTextBox . KeyDown -= HexInputTextBox_KeyDown ; }
313323 if ( this . HexInputTextBox != null ) { this . HexInputTextBox . LostFocus -= HexInputTextBox_LostFocus ; }
314324 if ( this . ColorModeComboBox != null ) { this . ColorModeComboBox . SelectionChanged -= ColorModeComboBox_SelectionChanged ; }
@@ -1325,6 +1335,20 @@ private void ColorSpectrum_GotFocus(object sender, RoutedEventArgs e)
13251335 return ;
13261336 }
13271337
1338+ /// <summary>
1339+ /// Event handler for when a color is selected from the palette.
1340+ /// This will update the current color.
1341+ /// </summary>
1342+ private void PaletteItemGridView_SelectionChanged ( object sender , SelectionChangedEventArgs e )
1343+ {
1344+ if ( ( sender as GridView ) ? . SelectedValue is not Color selectedColor )
1345+ {
1346+ return ;
1347+ }
1348+
1349+ this . Color = selectedColor ;
1350+ }
1351+
13281352 /// <summary>
13291353 /// Event handler for when the selected color representation changes.
13301354 /// This will convert between RGB and HSV.
0 commit comments