From 306712e4cce1f63be61357a5f1c0456374bebf0c Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Fri, 23 Dec 2022 12:33:28 +0000 Subject: [PATCH] make IsHoldingEnabledProperty and IsHoldWithMouseEnabledProperty attached properties in Gestures --- src/Avalonia.Base/Input/Gestures.cs | 30 +++++++++++++++++++++++++ src/Avalonia.Base/Input/InputElement.cs | 26 ++++++++++----------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/Avalonia.Base/Input/Gestures.cs b/src/Avalonia.Base/Input/Gestures.cs index a924b391ac..a91e37177a 100644 --- a/src/Avalonia.Base/Input/Gestures.cs +++ b/src/Avalonia.Base/Input/Gestures.cs @@ -13,6 +13,18 @@ namespace Avalonia.Input private static bool s_isHolding; private static CancellationTokenSource? s_holdCancellationToken; + /// + /// Defines the IsHoldingEnabled attached property. + /// + public static readonly AttachedProperty IsHoldingEnabledProperty = + AvaloniaProperty.RegisterAttached("IsHoldingEnabled", typeof(Gestures), true); + + /// + /// Defines the IsHoldWithMouseEnabled attached property. + /// + public static readonly AttachedProperty IsHoldWithMouseEnabledProperty = + AvaloniaProperty.RegisterAttached("IsHoldWithMouseEnabled", typeof(Gestures), false); + public static readonly RoutedEvent TappedEvent = RoutedEvent.Register( "Tapped", RoutingStrategies.Bubble, @@ -75,6 +87,24 @@ namespace Avalonia.Input RoutedEvent.Register( "PullGestureEnded", RoutingStrategies.Bubble, typeof(Gestures)); + public static bool GetIsHoldingEnabled(StyledElement element) + { + return element.GetValue(IsHoldingEnabledProperty); + } + public static void SetIsHoldingEnabled(StyledElement element, bool value) + { + element.SetValue(IsHoldingEnabledProperty, value); + } + + public static bool GetIsHoldWithMouseEnabled(StyledElement element) + { + return element.GetValue(IsHoldWithMouseEnabledProperty); + } + public static void SetIsHoldWithMouseEnabled(StyledElement element, bool value) + { + element.SetValue(IsHoldWithMouseEnabledProperty, value); + } + static Gestures() { InputElement.PointerPressedEvent.RouteFinished.Subscribe(PointerPressed); diff --git a/src/Avalonia.Base/Input/InputElement.cs b/src/Avalonia.Base/Input/InputElement.cs index 4a65134552..e1835241bf 100644 --- a/src/Avalonia.Base/Input/InputElement.cs +++ b/src/Avalonia.Base/Input/InputElement.cs @@ -45,18 +45,6 @@ namespace Avalonia.Input public static readonly StyledProperty CursorProperty = AvaloniaProperty.Register(nameof(Cursor), null, true); - /// - /// Defines the property. - /// - public static readonly StyledProperty IsHoldingEnabledProperty = - AvaloniaProperty.Register(nameof(IsHoldingEnabled), true); - - /// - /// Defines the property. - /// - public static readonly StyledProperty IsHoldWithMouseEnabledProperty = - AvaloniaProperty.Register(nameof(IsHoldWithMouseEnabled), false); - /// /// Defines the property. /// @@ -209,7 +197,19 @@ namespace Avalonia.Input /// Defines the event. /// public static readonly RoutedEvent DoubleTappedEvent = Gestures.DoubleTappedEvent; - + + /// + /// Defines the property. + /// + public static readonly StyledProperty IsHoldingEnabledProperty = + Gestures.IsHoldingEnabledProperty.AddOwner(); + + /// + /// Defines the property. + /// + public static readonly StyledProperty IsHoldWithMouseEnabledProperty = + Gestures.IsHoldWithMouseEnabledProperty.AddOwner(); + private bool _isEffectivelyEnabled = true; private bool _isFocused; private bool _isKeyboardFocusWithin;