using Avalonia.Input;
using Avalonia.Interactivity;
namespace Avalonia.Xaml.Interactions.Events;
///
///
///
public abstract class PointerEventsBehavior : InteractiveBehaviorBase
{
static PointerEventsBehavior()
{
RoutingStrategiesProperty.OverrideMetadata(
new StyledPropertyMetadata(
defaultValue: RoutingStrategies.Tunnel | RoutingStrategies.Bubble));
}
///
protected override void OnAttachedToVisualTree()
{
if (AssociatedObject is not null)
{
AssociatedObject.AddHandler(InputElement.PointerPressedEvent, PointerPressed, RoutingStrategies);
AssociatedObject.AddHandler(InputElement.PointerReleasedEvent, PointerReleased, RoutingStrategies);
AssociatedObject.AddHandler(InputElement.PointerMovedEvent, PointerMoved, RoutingStrategies);
}
}
///
protected override void OnDetachedFromVisualTree()
{
if (AssociatedObject is not null)
{
AssociatedObject.RemoveHandler(InputElement.PointerPressedEvent, PointerPressed);
AssociatedObject.RemoveHandler(InputElement.PointerReleasedEvent, PointerReleased);
AssociatedObject.RemoveHandler(InputElement.PointerMovedEvent, PointerMoved);
}
}
private void PointerPressed(object? sender, PointerPressedEventArgs e)
{
OnPointerPressed(sender, e);
}
private void PointerReleased(object? sender, PointerReleasedEventArgs e)
{
OnPointerReleased(sender, e);
}
private void PointerMoved(object? sender, PointerEventArgs e)
{
OnPointerMoved(sender, e);
}
///
///
///
///
///
protected virtual void OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
}
///
///
///
///
///
protected virtual void OnPointerReleased(object? sender, PointerReleasedEventArgs e)
{
}
///
///
///
///
///
protected virtual void OnPointerMoved(object? sender, PointerEventArgs e)
{
}
}