diff --git a/src/Avalonia.Base/Input/Gestures.cs b/src/Avalonia.Base/Input/Gestures.cs
index 06d90f1c27..b1fda35c28 100644
--- a/src/Avalonia.Base/Input/Gestures.cs
+++ b/src/Avalonia.Base/Input/Gestures.cs
@@ -13,13 +13,6 @@ namespace Avalonia.Input
private static bool s_isHolding;
private static CancellationTokenSource? s_holdCancellationToken;
- /* ///
- /// Defines the property.
- ///
- public static readonly AttachedProperty IsHoldWithMouseEnabledProperty =
- AvaloniaProperty.RegisterAttached(
- "IsHoldWithMouseEnabled");*/
-
public static readonly RoutedEvent TappedEvent = RoutedEvent.Register(
"Tapped",
RoutingStrategies.Bubble,
@@ -71,6 +64,9 @@ namespace Avalonia.Input
RoutedEvent.Register(
"PullGesture", RoutingStrategies.Bubble, typeof(Gestures));
+ ///
+ /// Occurs when a user performs a press and hold gesture (with a single touch, mouse, or pen/stylus contact).
+ ///
public static readonly RoutedEvent HoldingEvent =
RoutedEvent.Register(
"Holding", RoutingStrategies.Bubble, typeof(Gestures));
@@ -132,7 +128,7 @@ namespace Avalonia.Input
{
if(s_isHolding && ev.Source is Interactive i)
{
- i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled));
+ i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled, s_lastPressPoint, s_lastPointer.Type));
}
s_holdCancellationToken?.Cancel();
s_holdCancellationToken?.Dispose();
@@ -157,7 +153,7 @@ namespace Avalonia.Input
if (!token.IsCancellationRequested && e.Source is InputElement i && i.IsHoldingEnabled && ( e.Pointer.Type != PointerType.Mouse || i.IsHoldWithMouseEnabled))
{
s_isHolding = true;
- i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Started));
+ i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Started, s_lastPressPoint, s_lastPointer.Type));
}
}, TimeSpan.FromMilliseconds(300));
}
@@ -196,7 +192,7 @@ namespace Avalonia.Input
if(s_isHolding)
{
s_isHolding = false;
- i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Completed));
+ i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Completed, s_lastPressPoint, s_lastPointer!.Type));
}
else if (e.InitialPressMouseButton == MouseButton.Right)
{
@@ -241,7 +237,7 @@ namespace Avalonia.Input
if (s_isHolding && ev.Source is Interactive i)
{
- i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled));
+ i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled, s_lastPressPoint, s_lastPointer!.Type));
}
}
diff --git a/src/Avalonia.Base/Input/HoldingRoutedEventArgs.cs b/src/Avalonia.Base/Input/HoldingRoutedEventArgs.cs
index 5826c5b994..b9a877b2ed 100644
--- a/src/Avalonia.Base/Input/HoldingRoutedEventArgs.cs
+++ b/src/Avalonia.Base/Input/HoldingRoutedEventArgs.cs
@@ -5,18 +5,47 @@ namespace Avalonia.Input
{
public class HoldingRoutedEventArgs : RoutedEventArgs
{
+ ///
+ /// Gets the state of the event.
+ ///
public HoldingState HoldingState { get; }
-
- public HoldingRoutedEventArgs(HoldingState holdingState) : base(Gestures.HoldingEvent)
+
+ ///
+ /// Gets the location of the touch, mouse, or pen/stylus contact.
+ ///
+ public Point Position { get; }
+
+ ///
+ /// Gets the pointer type of the input source.
+ ///
+ public PointerType PointerType { get; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public HoldingRoutedEventArgs(HoldingState holdingState, Point position, PointerType pointerType) : base(Gestures.HoldingEvent)
{
HoldingState = holdingState;
+ Position = position;
+ PointerType = pointerType;
}
}
public enum HoldingState
{
+ ///
+ /// A single contact has been detected and a time threshold is crossed without the contact being lifted, another contact detected, or another gesture started.
+ ///
Started,
+
+ ///
+ /// The single contact is lifted.
+ ///
Completed,
+
+ ///
+ /// An additional contact is detected or a subsequent gesture (such as a slide) is detected.
+ ///
Cancelled,
}
}
diff --git a/src/Avalonia.Base/Input/InputElement.cs b/src/Avalonia.Base/Input/InputElement.cs
index 7f2cbec299..4a65134552 100644
--- a/src/Avalonia.Base/Input/InputElement.cs
+++ b/src/Avalonia.Base/Input/InputElement.cs
@@ -426,8 +426,7 @@ namespace Avalonia.Input
}
///
- /// Gets or sets a value that determines whether the Holding event can originate
- /// from that element.
+ /// Enables or disables support for the press and hold gesture through the left button on a mouse.
///
public bool IsHoldWithMouseEnabled
{
diff --git a/src/Avalonia.Controls/Control.cs b/src/Avalonia.Controls/Control.cs
index bb83f9e8bb..26db431a0e 100644
--- a/src/Avalonia.Controls/Control.cs
+++ b/src/Avalonia.Controls/Control.cs
@@ -375,9 +375,9 @@ namespace Avalonia.Controls
private void OnHoldEvent(object? sender, HoldingRoutedEventArgs e)
{
- if(e.HoldingState == HoldingState.Completed)
+ if(e.HoldingState == HoldingState.Started)
{
- // Trigger ContentRequest when hold is complete
+ // Trigger ContentRequest when hold has started
RaiseEvent(new ContextRequestedEventArgs());
}
}