diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs index ba6d8a98f69c..f905812c66bf 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs @@ -730,15 +730,7 @@ void PinchComplete(bool success) void UpdateDragAndDropGestureRecognizers() { - if (_container is null) - { - return; - } - - var view = Element as View; - IList? gestures = view?.GestureRecognizers; - - if (gestures is null) + if (_container is null || Element is not View view || view.GestureRecognizers is not IList gestures) { return; } @@ -812,16 +804,17 @@ void UpdatingGestureRecognizers() } } - _subscriptionFlags |= SubscriptionFlags.ContainerPgrPointerEventsSubscribed; - _container.PointerEntered += OnPgrPointerEntered; - _container.PointerExited += OnPgrPointerExited; - _container.PointerMoved += OnPgrPointerMoved; - _container.PointerPressed += OnPgrPointerPressed; - _container.PointerReleased += OnPgrPointerReleased; + bool hasPointerGesture = ElementGestureRecognizers.HasAnyGesturesFor(); + + if (hasPointerGesture) + { + SubscribePointerEvents(_container); + } bool hasSwipeGesture = gestures.HasAnyGesturesFor(); bool hasPinchGesture = gestures.HasAnyGesturesFor(); bool hasPanGesture = gestures.HasAnyGesturesFor(); + if (!hasSwipeGesture && !hasPinchGesture && !hasPanGesture) { return; @@ -840,6 +833,12 @@ void UpdatingGestureRecognizers() return; } + // Pan, pinch, and swipe gestures need pointer events if not subscribed yet. + if (!hasPointerGesture) + { + SubscribePointerEvents(_container); + } + _subscriptionFlags |= SubscriptionFlags.ContainerManipulationAndPointerEventsSubscribed; _container.ManipulationMode = ManipulationModes.Scale | ManipulationModes.TranslateX | ManipulationModes.TranslateY; _container.ManipulationDelta += OnManipulationDelta; @@ -848,6 +847,17 @@ void UpdatingGestureRecognizers() _container.PointerCanceled += OnPointerCanceled; } + void SubscribePointerEvents(FrameworkElement container) + { + _subscriptionFlags |= SubscriptionFlags.ContainerPgrPointerEventsSubscribed; + + container.PointerEntered += OnPgrPointerEntered; + container.PointerExited += OnPgrPointerExited; + container.PointerMoved += OnPgrPointerMoved; + container.PointerPressed += OnPgrPointerPressed; + container.PointerReleased += OnPgrPointerReleased; + } + void HandleTapped(object sender, TappedRoutedEventArgs tappedRoutedEventArgs) { tappedRoutedEventArgs.Handled = true;