-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Color picker fixes #4134
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
Color picker fixes #4134
Changes from 2 commits
90e8a34
f448ee3
bc05c86
e23a895
dde93f3
79f2931
9f20cf4
4fd1609
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls | |
[TemplatePart(Name = nameof(ColorPicker.CheckeredBackground8Border), Type = typeof(Border))] | ||
[TemplatePart(Name = nameof(ColorPicker.CheckeredBackground9Border), Type = typeof(Border))] | ||
[TemplatePart(Name = nameof(ColorPicker.CheckeredBackground10Border), Type = typeof(Border))] | ||
[TemplatePart(Name = nameof(ColorPicker.ColorPanelSelector), Type = typeof(ListBox))] | ||
[TemplatePart(Name = nameof(ColorPicker.ColorSpectrumControl), Type = typeof(ColorSpectrum))] | ||
[TemplatePart(Name = nameof(ColorPicker.ColorSpectrumAlphaSlider), Type = typeof(ColorPickerSlider))] | ||
[TemplatePart(Name = nameof(ColorPicker.ColorSpectrumThirdDimensionSlider), Type = typeof(ColorPickerSlider))] | ||
|
@@ -78,6 +79,7 @@ public partial class ColorPicker : Microsoft.UI.Xaml.Controls.ColorPicker | |
private Color? updatedRgbColor = null; | ||
private DispatcherQueueTimer dispatcherQueueTimer = null; | ||
|
||
private ListBox ColorPanelSelector; | ||
private ColorSpectrum ColorSpectrumControl; | ||
private ColorPickerSlider ColorSpectrumAlphaSlider; | ||
private ColorPickerSlider ColorSpectrumThirdDimensionSlider; | ||
|
@@ -177,6 +179,8 @@ protected override void OnApplyTemplate() | |
// We need to disconnect old events first | ||
this.ConnectEvents(false); | ||
|
||
this.ColorPanelSelector = this.GetTemplateChild<ListBox>(nameof(ColorPanelSelector)); | ||
|
||
this.ColorSpectrumControl = this.GetTemplateChild<ColorSpectrum>(nameof(ColorSpectrumControl)); | ||
this.ColorSpectrumAlphaSlider = this.GetTemplateChild<ColorPickerSlider>(nameof(ColorSpectrumAlphaSlider)); | ||
this.ColorSpectrumThirdDimensionSlider = this.GetTemplateChild<ColorPickerSlider>(nameof(ColorSpectrumThirdDimensionSlider)); | ||
|
@@ -216,6 +220,7 @@ protected override void OnApplyTemplate() | |
|
||
base.OnApplyTemplate(); | ||
this.UpdateVisualState(false); | ||
this.ValidateSelectedPanel(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an issue with validating and updating the selected panel only here. If the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an existing issue, correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was waiting to see if its considered enough of an issue to fix. The changes now will work as long as the properties are updated in XAML which is by far the largest use case. |
||
this.isInitialized = true; | ||
this.SetActiveColorRepresentation(ColorRepresentation.Rgba); | ||
this.UpdateColorControlValues(); // TODO: This will also connect events after, can we optimize vs. doing it twice with the ConnectEvents above? | ||
|
@@ -1065,6 +1070,48 @@ private void SetDefaultPalette() | |
return; | ||
} | ||
|
||
/// <summary> | ||
/// Validates and updates the current 'tab' or 'panel' selection. | ||
/// If the currently selected tab is collapsed, the next visible tab will be selected. | ||
/// </summary> | ||
private void ValidateSelectedPanel() | ||
{ | ||
object selectedItem = null; | ||
|
||
if (this.ColorPanelSelector != null) | ||
{ | ||
if (this.ColorPanelSelector.SelectedItem == null && | ||
this.ColorPanelSelector.Items.Count > 0) | ||
{ | ||
// As a failsafe, forcefully select the first item | ||
selectedItem = this.ColorPanelSelector.Items[0]; | ||
} | ||
else | ||
{ | ||
selectedItem = this.ColorPanelSelector.SelectedItem; | ||
} | ||
|
||
if (selectedItem is UIElement selectedElement && | ||
selectedElement.Visibility == Visibility.Collapsed) | ||
{ | ||
// Select the first visible item instead | ||
foreach (object item in this.ColorPanelSelector.Items) | ||
{ | ||
if (item is UIElement element && | ||
element.Visibility == Visibility.Visible) | ||
{ | ||
selectedItem = item; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
this.ColorPanelSelector.SelectedItem = selectedItem; | ||
} | ||
|
||
return; | ||
} | ||
|
||
/*************************************************************************************** | ||
* | ||
* Color Update Timer | ||
|
Uh oh!
There was an error while loading. Please reload this page.