123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using Avalonia.Input;
- using Avalonia.Interactivity;
- namespace Avalonia.Xaml.Interactions.Events;
- /// <summary>
- ///
- /// </summary>
- public abstract class PointerEventsBehavior : InteractiveBehaviorBase
- {
- static PointerEventsBehavior()
- {
- RoutingStrategiesProperty.OverrideMetadata<PointerEventsBehavior>(
- new StyledPropertyMetadata<RoutingStrategies>(
- defaultValue: RoutingStrategies.Tunnel | RoutingStrategies.Bubble));
- }
- /// <inheritdoc />
- 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);
- }
- }
- /// <inheritdoc />
- 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);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void OnPointerPressed(object? sender, PointerPressedEventArgs e)
- {
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void OnPointerReleased(object? sender, PointerReleasedEventArgs e)
- {
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void OnPointerMoved(object? sender, PointerEventArgs e)
- {
- }
- }
|