diff --git a/src/Avalonia.Controls.ColorPicker/ColorView/ColorView.Properties.cs b/src/Avalonia.Controls.ColorPicker/ColorView/ColorView.Properties.cs index a3267d88f2..a4897c99a2 100644 --- a/src/Avalonia.Controls.ColorPicker/ColorView/ColorView.Properties.cs +++ b/src/Avalonia.Controls.ColorPicker/ColorView/ColorView.Properties.cs @@ -8,7 +8,6 @@ namespace Avalonia.Controls /// public partial class ColorView { - // SelectedTabIndex // IsColorModelSelectorVisible // IsComponentSliderVisible @@ -198,6 +197,14 @@ namespace Avalonia.Controls nameof(MinValue), 0); + /// + /// Defines the property. + /// + public static readonly StyledProperty SelectedTabIndexProperty = + AvaloniaProperty.Register( + nameof(SelectedTabIndex), + (int)ColorViewTab.Spectrum); + /// /// Defines the property. /// @@ -413,6 +420,15 @@ namespace Avalonia.Controls set => SetValue(MinValueProperty, value); } + /// + /// Gets or sets the index of the selected subview/tab. + /// + public int SelectedTabIndex + { + get => GetValue(SelectedTabIndexProperty); + set => SetValue(SelectedTabIndexProperty, value); + } + /// public bool ShowAccentColors { diff --git a/src/Avalonia.Controls.ColorPicker/ColorView/ColorView.cs b/src/Avalonia.Controls.ColorPicker/ColorView/ColorView.cs index d0ee5f9acd..9809f1312b 100644 --- a/src/Avalonia.Controls.ColorPicker/ColorView/ColorView.cs +++ b/src/Avalonia.Controls.ColorPicker/ColorView/ColorView.cs @@ -73,7 +73,10 @@ namespace Avalonia.Controls /// Validates the selected subview/tab taking into account the visibility of each subview/tab /// as well as the current selection. /// - private void ValidateSelectedTab() + /// + /// Derived controls may re-implement this based on their default style / control template. + /// + protected virtual void ValidateSelectedTab() { if (_tabControl != null && _tabControl.Items != null) @@ -135,6 +138,8 @@ namespace Avalonia.Controls _tabControl.SelectedItem = null; _tabControl.IsVisible = false; } + + SelectedTabIndex = _tabControl.SelectedIndex; } return; @@ -232,6 +237,15 @@ namespace Avalonia.Controls ValidateSelectedTab(); }, DispatcherPriority.Background); } + else if (change.Property == SelectedTabIndexProperty) + { + // Again, it is necessary to wait for the SelectedTabIndex value to + // be applied to the TabControl through binding before validation occurs. + Dispatcher.UIThread.Post(() => + { + ValidateSelectedTab(); + }, DispatcherPriority.Background); + } base.OnPropertyChanged(change); } diff --git a/src/Avalonia.Controls.ColorPicker/ColorView/ColorViewTab.cs b/src/Avalonia.Controls.ColorPicker/ColorView/ColorViewTab.cs index 534e833631..8e3433d819 100644 --- a/src/Avalonia.Controls.ColorPicker/ColorView/ColorViewTab.cs +++ b/src/Avalonia.Controls.ColorPicker/ColorView/ColorViewTab.cs @@ -1,23 +1,26 @@ namespace Avalonia.Controls { /// - /// Defines a specific subview (tab) within the . + /// Defines a specific subview/tab within the . /// + /// + /// This is indexed to match the default control template ordering. + /// public enum ColorViewTab { /// - /// The components subview with sliders and numeric input boxes. + /// The color spectrum subview with a box/ring spectrum and sliders. /// - Components, + Spectrum = 0, /// /// The color palette subview with a grid of selectable colors. /// - Palette, + Palette = 1, /// - /// The color spectrum subview with a box/ring spectrum and sliders. + /// The components subview with sliders and numeric input boxes. /// - Spectrum, + Components = 2, } } diff --git a/src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorView.xaml b/src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorView.xaml index 420e3b2ae9..d6bf83ff44 100644 --- a/src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorView.xaml +++ b/src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorView.xaml @@ -112,7 +112,8 @@ + Width="350" + SelectedIndex="{Binding SelectedTabIndex, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"> 0,0,0,0