diff --git a/src/Uno.Toolkit.UI/Controls/ZoomContentControl/ZoomContentControl.cs b/src/Uno.Toolkit.UI/Controls/ZoomContentControl/ZoomContentControl.cs index f2a77770e..a5afece0e 100644 --- a/src/Uno.Toolkit.UI/Controls/ZoomContentControl/ZoomContentControl.cs +++ b/src/Uno.Toolkit.UI/Controls/ZoomContentControl/ZoomContentControl.cs @@ -289,10 +289,11 @@ private void OnPointerMoved(object sender, PointerRoutedEventArgs e) if (_capturedPointerContext is { } context) { var position = e.GetCurrentPoint(this).Position; - var delta = context.Position - position; + var delta = new Point(context.Position.X - position.X, context.Position.Y - position.Y); delta.X *= -1; - SetScrollValue(context.ScrollOffset + delta); + var newScrollOffset = new Point(context.ScrollOffset.X + delta.X, context.ScrollOffset.Y + delta.Y); + SetScrollValue(newScrollOffset); } } @@ -306,7 +307,7 @@ private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e) #if IS_WINUI p.PointerDeviceType != PointerDeviceType.Mouse #else - p.PointerDevice.PointerDeviceType != PointerDeviceType.Mouse + p.PointerDevice.PointerDeviceType != PointerDeviceType.Mouse #endif ) return; @@ -315,16 +316,21 @@ private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e) { if (!IsZoomAllowed) return; - var oldPosition = (p.Position - vp.ActualSize.ToPoint().DivideBy(2)) - ScrollValue.MultiplyBy(1, -1); - var basePosition = oldPosition.DivideBy(ZoomLevel); + var oldPositionX = p.Position.X - (vp.ActualSize.X / 2) - ScrollValue.X * 1; + var oldPositionY = p.Position.Y - (vp.ActualSize.Y / 2) - ScrollValue.Y * (-1); + var oldPosition = new Point(oldPositionX, oldPositionY); + + var basePosition = new Point(oldPosition.X / ZoomLevel, oldPosition.Y / ZoomLevel); var newZoom = ZoomLevel * (1 + p.Properties.MouseWheelDelta * ScaleWheelRatio); //var newZoom = ZoomLevel + Math.Sign(p.Properties.MouseWheelDelta); newZoom = Math.Clamp(newZoom, MinZoomLevel, MaxZoomLevel); - var newPosition = basePosition.MultiplyBy(newZoom); - var delta = (newPosition - oldPosition).MultiplyBy(-1, 1); - var offset = ScrollValue + delta; + var newPosition = new Point(basePosition.X * newZoom, basePosition.Y * newZoom); + var deltaX = newPosition.X - oldPosition.X; + var deltaY = newPosition.Y - oldPosition.Y; + var delta = new Point(deltaX * -1, deltaY * 1); + var offset = new Point(ScrollValue.X + delta.X, ScrollValue.Y + delta.Y); // note: updating ZoomLevel can have side effects on ScrollValue: // ZoomLevel --UpdateScrollBars-> ScrollBar.Maximum --clamp-> ScrollBar.Value --bound-> H/VScrollValue @@ -342,7 +348,7 @@ private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e) var delta = e.KeyModifiers.HasFlag(Windows.System.VirtualKeyModifiers.Shift) ? new Point(magnitude, 0) : new Point(0, -magnitude); - var offset = ScrollValue + delta; + var offset = new Point(ScrollValue.X + delta.X, ScrollValue.Y + delta.Y); SetScrollValue(offset); e.Handled = true;