Skip to content

Switch ColorPicker to Derive from WinUI Controls #4010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
5 commits merged into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -52,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

Expand Down Expand Up @@ -122,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<Color>());
Expand Down Expand Up @@ -486,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;
Expand Down Expand Up @@ -1125,7 +1127,7 @@ private void DispatcherQueueTimer_Tick(object sender, object e)
***************************************************************************************/

/// <summary>
/// Callback for when the <see cref="Windows.UI.Xaml.Controls.ColorPicker.Color"/> dependency property value changes.
/// Callback for when the <see cref="Microsoft.UI.Xaml.Controls.ColorPicker.Color"/> dependency property value changes.
/// </summary>
private void OnColorChanged(DependencyObject d, DependencyProperty e)
{
Expand Down Expand Up @@ -1226,7 +1228,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.
/// </summary>
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<SolidColorBrush x:Key="CheckerboardColor0">
<SolidColorBrush.Color>
Expand Down Expand Up @@ -120,23 +121,23 @@
Orientation="Vertical" />
<!-- Keep in mind the spectrum is always HSV -->
<!-- This must also not be named 'ColorSpectrum' to differentiate from the base class -->
<ColorSpectrum x:Name="ColorSpectrumControl"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
MinWidth="256"
MinHeight="256"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AutomationProperties.Name="Third Dimension"
Components="{TemplateBinding ColorSpectrumComponents}"
MaxHue="{TemplateBinding MaxHue}"
MaxSaturation="{TemplateBinding MaxSaturation}"
MaxValue="{TemplateBinding MaxValue}"
MinHue="{TemplateBinding MinHue}"
MinSaturation="{TemplateBinding MinSaturation}"
MinValue="{TemplateBinding MinValue}"
Shape="{TemplateBinding ColorSpectrumShape}" />
<winuiprimitives:ColorSpectrum x:Name="ColorSpectrumControl"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
MinWidth="256"
MinHeight="256"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AutomationProperties.Name="Third Dimension"
Components="{TemplateBinding ColorSpectrumComponents}"
MaxHue="{TemplateBinding MaxHue}"
MaxSaturation="{TemplateBinding MaxSaturation}"
MaxValue="{TemplateBinding MaxValue}"
MinHue="{TemplateBinding MinHue}"
MinSaturation="{TemplateBinding MinSaturation}"
MinValue="{TemplateBinding MinValue}"
Shape="{TemplateBinding ColorSpectrumShape}" />
<primitives:ColorPickerSlider x:Name="ColorSpectrumAlphaSlider"
Grid.Row="1"
Grid.RowSpan="2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down