diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs index 08e5a75e2585..ab92747dd49d 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs @@ -191,7 +191,7 @@ void HandleDragLeave(object sender, Microsoft.UI.Xaml.DragEventArgs e) // for example // e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy; // Even if AcceptedOperation is already set to Copy it will cause the copy animation - // to remain even after the the dragged element has left + // to remain even after the dragged element has left if (!dragEventArgs.PlatformArgs?.Handled ?? true && operationPriorToSend != dragEventArgs.AcceptedOperation) { var result = (int)dragEventArgs.AcceptedOperation; @@ -261,21 +261,18 @@ void HandleDragStarting(UIElement sender, Microsoft.UI.Xaml.DragStartingEventArg { SendEventArgs(rec => { - var view = Element as View; - - if (!rec.CanDrag || view is null) + if (!rec.CanDrag || Element is not View view) { e.Cancel = true; return; } - var handler = sender as IViewHandler; var args = rec.SendDragStarting(view, (relativeTo) => GetPosition(relativeTo, e), new PlatformDragStartingEventArgs(sender, e)); e.Data.Properties[_doNotUsePropertyString] = args.Data; #pragma warning disable CS0618 // Type or member is obsolete - if ((!args.Handled || (!args.PlatformArgs?.Handled ?? true)) && handler != null) + if ((!args.Handled || (!args.PlatformArgs?.Handled ?? true)) && sender is IViewHandler handler) #pragma warning restore CS0618 // Type or member is obsolete { if (handler?.PlatformView is UI.Xaml.Controls.Image nativeImage && @@ -509,8 +506,6 @@ void HandlePinch(ManipulationDeltaRoutedEventArgs e, View view) return; } - _isPinching = true; - if (e.OriginalSource is UIElement container) { global::Windows.Foundation.Point translationPoint = container.TransformToVisual(Container).TransformPoint(e.Position); @@ -541,13 +536,13 @@ void OnManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs SwipeComplete(true); PinchComplete(true); PanComplete(true); + + _fingers.Clear(); } void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { - var view = Element as View; - - if (view == null) + if (Element is not View view) { return; } @@ -559,40 +554,33 @@ void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) void OnManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e) { - var view = Element as View; - if (view == null) + if (Element is not View view) { return; } + _isPinching = true; _wasPinchGestureStartedSent = false; _wasPanGestureStartedSent = false; } void OnPointerCanceled(object sender, PointerRoutedEventArgs e) { - uint id = e.Pointer.PointerId; - if (_fingers.Contains(id)) - { - _fingers.Remove(id); - } - SwipeComplete(false); PinchComplete(false); PanComplete(false); + + _fingers.Clear(); } void OnPointerExited(object sender, PointerRoutedEventArgs e) { + SwipeComplete(true); + if (!_isPanning) { - uint id = e.Pointer.PointerId; - if (_fingers.Contains(id)) - _fingers.Remove(id); + _fingers.Remove(e.Pointer.PointerId); } - - SwipeComplete(true); - PinchComplete(true); } void OnPointerPressed(object sender, PointerRoutedEventArgs e) @@ -606,15 +594,10 @@ void OnPointerPressed(object sender, PointerRoutedEventArgs e) void OnPointerReleased(object sender, PointerRoutedEventArgs e) { - uint id = e.Pointer.PointerId; - if (_fingers.Contains(id)) - { - _fingers.Remove(id); - } - SwipeComplete(true); - PinchComplete(true); PanComplete(true); + + _fingers.Remove(e.Pointer.PointerId); } void OnPgrPointerEntered(object sender, PointerRoutedEventArgs e) @@ -708,8 +691,7 @@ void OnPgrPointerReleased(object sender, PointerRoutedEventArgs e) private void HandlePgrPointerEvent(PointerRoutedEventArgs e, Action SendPointerEvent) { - var view = Element as View; - if (view == null) + if (Element is not View view) { return; } @@ -776,8 +758,7 @@ bool IsPointerEventRelevantToCurrentElement(PointerRoutedEventArgs e) void OnTap(object sender, RoutedEventArgs e) { - var view = Element as View; - if (view == null) + if (Element is not View view) { return; } @@ -853,8 +834,7 @@ bool ValidateGesture(TapGestureRecognizer g) void SwipeComplete(bool success) { - var view = Element as View; - if (view == null || !_isSwiping) + if (Element is not View view || !_isSwiping) { return; } @@ -872,8 +852,7 @@ void SwipeComplete(bool success) void PanComplete(bool success) { - var view = Element as View; - if (view == null || !_isPanning) + if (Element is not View view || !_isPanning) { return; } @@ -896,8 +875,7 @@ void PanComplete(bool success) void PinchComplete(bool success) { - var view = Element as View; - if (view is null || !_isPinching) + if (Element is not View view || !_isPinching) { return; }