From a50d606a5a51eb7fe052ad66944bf937863211dc Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 2 Feb 2022 01:02:31 -0500 Subject: [PATCH] Add splitbutton pressed state back --- .../SplitButton/SplitButton.cs | 8 ++++++- .../Controls/SplitButton.xaml | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/SplitButton/SplitButton.cs b/src/Avalonia.Controls/SplitButton/SplitButton.cs index 4cacc2789f..f1d07b2679 100644 --- a/src/Avalonia.Controls/SplitButton/SplitButton.cs +++ b/src/Avalonia.Controls/SplitButton/SplitButton.cs @@ -1,6 +1,7 @@ using System; using System.Windows.Input; using Avalonia.Controls.Metadata; +using Avalonia.Controls.Mixins; using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Interactivity; @@ -12,10 +13,11 @@ namespace Avalonia.Controls /// A button with primary and secondary parts that can each be pressed separately. /// The primary part behaves like a and the secondary part opens a flyout. /// - [PseudoClasses(pcFlyoutOpen)] + [PseudoClasses(pcFlyoutOpen, pcPressed)] public class SplitButton : ContentControl, ICommandSource { protected const string pcChecked = ":checked"; + protected const string pcPressed = ":pressed"; protected const string pcFlyoutOpen = ":flyout-open"; /// @@ -61,6 +63,7 @@ namespace Avalonia.Controls private bool _commandCanExecute = true; private bool _isAttachedToLogicalTree = false; private bool _isFlyoutOpen = false; + private bool _isKeyboardPressed = false; private IDisposable? _flyoutPropertyChangedDisposable; @@ -144,6 +147,7 @@ namespace Avalonia.Controls protected void UpdatePseudoClasses() { PseudoClasses.Set(pcFlyoutOpen, _isFlyoutOpen); + PseudoClasses.Set(pcPressed, _isKeyboardPressed); PseudoClasses.Set(pcChecked, InternalIsChecked); } @@ -333,6 +337,7 @@ namespace Avalonia.Controls if (key == Key.Space || key == Key.Enter) // Key.GamepadA is not currently supported { + _isKeyboardPressed = true; UpdatePseudoClasses(); } @@ -346,6 +351,7 @@ namespace Avalonia.Controls if (key == Key.Space || key == Key.Enter) // Key.GamepadA is not currently supported { + _isKeyboardPressed = false; UpdatePseudoClasses(); // Consider this a click on the primary button diff --git a/src/Avalonia.Themes.Fluent/Controls/SplitButton.xaml b/src/Avalonia.Themes.Fluent/Controls/SplitButton.xaml index 3425485540..bf192af673 100644 --- a/src/Avalonia.Themes.Fluent/Controls/SplitButton.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/SplitButton.xaml @@ -125,6 +125,17 @@ + + + + + + + +