From ff39e4217cd3036c5350246ea2431ddd32d03917 Mon Sep 17 00:00:00 2001 From: robloo Date: Thu, 22 Apr 2021 23:29:15 -0400 Subject: [PATCH 1/2] Switch to the WinUI ColorSpectrum --- .../ColorPicker/ColorPicker.cs | 3 +- .../ColorPicker/ColorPicker.xaml | 37 ++++++++++--------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs index 98ed480a8c7..ec58cc3e7b7 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs @@ -15,6 +15,7 @@ using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Media; using ColorPickerSlider = Microsoft.Toolkit.Uwp.UI.Controls.Primitives.ColorPickerSlider; +using ColorSpectrum = Microsoft.UI.Xaml.Controls.Primitives.ColorSpectrum; namespace Microsoft.Toolkit.Uwp.UI.Controls { @@ -1226,7 +1227,7 @@ private void CustomPaletteColors_CollectionChanged(object sender, NotifyCollecti /// Event handler for when the color spectrum color is changed. /// This occurs when the user presses on the spectrum to select a new color. /// - private void ColorSpectrum_ColorChanged(ColorSpectrum sender, Windows.UI.Xaml.Controls.ColorChangedEventArgs args) + private void ColorSpectrum_ColorChanged(ColorSpectrum sender, Microsoft.UI.Xaml.Controls.ColorChangedEventArgs args) { // It is OK in this case to use the RGB representation this.ScheduleColorUpdate(this.ColorSpectrumControl.Color); diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.xaml b/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.xaml index 120ed76bf49..b9f25bd0664 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.xaml @@ -4,7 +4,8 @@ xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters" xmlns:localconverters="using:Microsoft.Toolkit.Uwp.UI.Controls.ColorPickerConverters" xmlns:primitives="using:Microsoft.Toolkit.Uwp.UI.Controls.Primitives" - xmlns:ui="using:Microsoft.Toolkit.Uwp.UI"> + xmlns:ui="using:Microsoft.Toolkit.Uwp.UI" + xmlns:winuiprimitives="using:Microsoft.UI.Xaml.Controls.Primitives"> @@ -120,23 +121,23 @@ Orientation="Vertical" /> - + Date: Fri, 23 Apr 2021 00:22:17 -0400 Subject: [PATCH 2/2] Derive from the WinUI ColorPicker --- .../ColorPicker/ColorPicker.cs | 17 +++++++++-------- .../ColorPicker/ColorPickerButton.cs | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs index ec58cc3e7b7..6d8ce7d30ef 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs @@ -53,7 +53,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501:Statement should not be on a single line", Justification = "Inline brackets are used to improve code readability with repeated null checks.")] [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1025:Code should not contain multiple whitespace in a row", Justification = "Whitespace is used to align code in columns for readability.")] [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1306:Field names should begin with lower-case letter", Justification = "Only template parts start with a capital letter. This differentiates them from other fields.")] - public partial class ColorPicker : Windows.UI.Xaml.Controls.ColorPicker + public partial class ColorPicker : Microsoft.UI.Xaml.Controls.ColorPicker { internal Color CheckerBackgroundColor { get; set; } = Color.FromArgb(0x19, 0x80, 0x80, 0x80); // Overridden later @@ -123,6 +123,7 @@ public partial class ColorPicker : Windows.UI.Xaml.Controls.ColorPicker public ColorPicker() { this.DefaultStyleKey = typeof(ColorPicker); + this.DefaultStyleResourceUri = new System.Uri("ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls.Input/Themes/Generic.xaml"); // Setup collections this.SetValue(CustomPaletteColorsProperty, new ObservableCollection()); @@ -487,22 +488,22 @@ private ColorChannel GetActiveColorSpectrumThirdDimension() { switch (this.ColorSpectrumComponents) { - case Windows.UI.Xaml.Controls.ColorSpectrumComponents.SaturationValue: - case Windows.UI.Xaml.Controls.ColorSpectrumComponents.ValueSaturation: + case Microsoft.UI.Xaml.Controls.ColorSpectrumComponents.SaturationValue: + case Microsoft.UI.Xaml.Controls.ColorSpectrumComponents.ValueSaturation: { // Hue return ColorChannel.Channel1; } - case Windows.UI.Xaml.Controls.ColorSpectrumComponents.HueValue: - case Windows.UI.Xaml.Controls.ColorSpectrumComponents.ValueHue: + case Microsoft.UI.Xaml.Controls.ColorSpectrumComponents.HueValue: + case Microsoft.UI.Xaml.Controls.ColorSpectrumComponents.ValueHue: { // Saturation return ColorChannel.Channel2; } - case Windows.UI.Xaml.Controls.ColorSpectrumComponents.HueSaturation: - case Windows.UI.Xaml.Controls.ColorSpectrumComponents.SaturationHue: + case Microsoft.UI.Xaml.Controls.ColorSpectrumComponents.HueSaturation: + case Microsoft.UI.Xaml.Controls.ColorSpectrumComponents.SaturationHue: { // Value return ColorChannel.Channel3; @@ -1126,7 +1127,7 @@ private void DispatcherQueueTimer_Tick(object sender, object e) ***************************************************************************************/ /// - /// Callback for when the dependency property value changes. + /// Callback for when the dependency property value changes. /// private void OnColorChanged(DependencyObject d, DependencyProperty e) { diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPickerButton.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPickerButton.cs index 057735d3dd9..28c8cd07674 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPickerButton.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPickerButton.cs @@ -142,7 +142,7 @@ protected override void OnApplyTemplate() } } - private void ColorPicker_ColorChanged(Windows.UI.Xaml.Controls.ColorPicker sender, ColorChangedEventArgs args) + private void ColorPicker_ColorChanged(Microsoft.UI.Xaml.Controls.ColorPicker sender, Microsoft.UI.Xaml.Controls.ColorChangedEventArgs args) { SelectedColor = args.NewColor; }