1
0
Эх сурвалжийг харах

make IsHoldingEnabledProperty and IsHoldWithMouseEnabledProperty attached properties in Gestures

Emmanuel Hansen 2 жил өмнө
parent
commit
306712e4cc

+ 30 - 0
src/Avalonia.Base/Input/Gestures.cs

@@ -13,6 +13,18 @@ namespace Avalonia.Input
         private static bool s_isHolding;
         private static CancellationTokenSource? s_holdCancellationToken;
 
+        /// <summary>
+        /// Defines the IsHoldingEnabled attached property.
+        /// </summary>
+        public static readonly AttachedProperty<bool> IsHoldingEnabledProperty =
+            AvaloniaProperty.RegisterAttached<StyledElement, bool>("IsHoldingEnabled", typeof(Gestures), true);
+
+        /// <summary>
+        /// Defines the IsHoldWithMouseEnabled attached property.
+        /// </summary>
+        public static readonly AttachedProperty<bool> IsHoldWithMouseEnabledProperty =
+            AvaloniaProperty.RegisterAttached<StyledElement, bool>("IsHoldWithMouseEnabled", typeof(Gestures), false);
+
         public static readonly RoutedEvent<TappedEventArgs> TappedEvent = RoutedEvent.Register<TappedEventArgs>(
             "Tapped",
             RoutingStrategies.Bubble,
@@ -75,6 +87,24 @@ namespace Avalonia.Input
             RoutedEvent.Register<PullGestureEndedEventArgs>(
                 "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);

+ 13 - 13
src/Avalonia.Base/Input/InputElement.cs

@@ -45,18 +45,6 @@ namespace Avalonia.Input
         public static readonly StyledProperty<Cursor?> CursorProperty =
             AvaloniaProperty.Register<InputElement, Cursor?>(nameof(Cursor), null, true);
 
-        /// <summary>
-        /// Defines the <see cref="IsHoldingEnabled"/> property.
-        /// </summary>
-        public static readonly StyledProperty<bool> IsHoldingEnabledProperty =
-            AvaloniaProperty.Register<InputElement, bool>(nameof(IsHoldingEnabled), true);
-
-        /// <summary>
-        /// Defines the <see cref="IsHoldWithMouseEnabled"/> property.
-        /// </summary>
-        public static readonly StyledProperty<bool> IsHoldWithMouseEnabledProperty =
-            AvaloniaProperty.Register<InputElement, bool>(nameof(IsHoldWithMouseEnabled), false);
-
         /// <summary>
         /// Defines the <see cref="IsKeyboardFocusWithin"/> property.
         /// </summary>
@@ -209,7 +197,19 @@ namespace Avalonia.Input
         /// Defines the <see cref="DoubleTapped"/> event.
         /// </summary>
         public static readonly RoutedEvent<TappedEventArgs> DoubleTappedEvent = Gestures.DoubleTappedEvent;
-        
+
+        /// <summary>
+        /// Defines the <see cref="IsHoldingEnabled"/> property.
+        /// </summary>
+        public static readonly StyledProperty<bool> IsHoldingEnabledProperty =
+            Gestures.IsHoldingEnabledProperty.AddOwner<InputElement>();
+
+        /// <summary>
+        /// Defines the <see cref="IsHoldWithMouseEnabled"/> property.
+        /// </summary>
+        public static readonly StyledProperty<bool> IsHoldWithMouseEnabledProperty =
+            Gestures.IsHoldWithMouseEnabledProperty.AddOwner<InputElement>();
+
         private bool _isEffectivelyEnabled = true;
         private bool _isFocused;
         private bool _isKeyboardFocusWithin;