wieslawsoltes / PanAndZoom

Pan and zoom control for Avalonia.
http://wieslawsoltes.github.io/PanAndZoom/
MIT License
337 stars 44 forks source link

BUG: Zooming in makes the offset reset #78

Open aviabdg opened 2 months ago

aviabdg commented 2 months ago

I have a Window with UserControl (800x450), ScrollViewer -> ZoomBorder -> Canvas -> Image at 0, 0. The Image contains a Bitmap of size 8000x5153. When the application loads I set the starting zoom level to 0.25. The window displays the image. When I use the mousewheel to zoom in at the bottom right corner of the bitmap it will zoom in and then jump to an offset at the top left.

The debug output on the ZoomChanged event:

[11:49:45 DBG] Zoom changed: 0.3 at -364.5999999999999, -222.5999999999999
[11:49:45 DBG] Zoom changed: 0.432 at -1327.1439999999998, -812.4639785156248
[11:49:45 DBG] Zoom changed: 0.432 at -1327.1439999999998, -810.4639785156248
[11:49:47 DBG] Zoom changed: 0.5184 at -1957.1727999999996, -1196.1567742187497
[11:49:47 DBG] Zoom changed: 0.5184 at -1957.1727999999994, -1195.1567742187497
[11:49:47 DBG] Zoom changed: 0.62208 at -2713.207359999999, -1657.7881290624996
[11:49:47 DBG] Zoom changed: 0.62208 at -2713.2073599999985, -1656.7881290624996
[11:49:47 DBG] Zoom changed: 0.7464959999999999 at -3620.448831999998, -2211.7457578124995
[11:49:47 DBG] Zoom changed: 0.7464959999999999 at -3620.448831999998, -2210.7457578124995
[11:49:47 DBG] Zoom changed: 1.0749542399999998 at -6015.566318079997, -3675.39389125
[11:49:47 DBG] Zoom changed: 1.0749542399999998 at -187.6854169599992, -93.34179327999982

You can see that the offset jumps from -6015.566318079997, -3675.39389125 to -187.6854169599992, -93.34179327999982.

The further from 0, 0 you zoom the quicker it will jump.

Windows 10 .NET 8.0 Avalonia 11.0.11 PanAndZoom 11.0.0.3

Edit: the same happens with 11.1.0-rc1

andrewzli commented 1 month ago

I have the same problem. It seems to be somehow related to the ScrollViewer. When I removed the ScrollViewer, the offset stopped jumping. For now, I've commented out the ScrollViewer but I'll need to add it back in at some point