Imagine you have a canvas that you want to scale to a very high value, and then enable panning.
A good example is a geographic tool that should allow panning with the βscalingβ of levels from the scale of the entire earth to a level of several meters.
I found that if you scale to more than, say, 500,000, the translation becomes very unstable, but ONLY if you look far from the canvas on the origin of 0.0!
I tried to translate canvas using RenderTransform. And I tried it, literally moving another window over a scalable canvas. I also saw the same problem in the application for another application.
The following sample code provides panning (clicking and dragging) at two different zoom locations. If you are implementing the code, you can click one button to increase it to 0.0, where you will find a nice, smooth mouse movement. Then use another button to increase to 200, 200 and smoothly pan more!
Any idea why this is or how it can be fixed?
XAML for sample:
<Window x:Class="TestPanZoom.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="500" Width="500" Loaded="Window_Loaded"> <Grid PreviewMouseLeftButtonDown="Grid_PreviewMouseLeftButtonDown" MouseMove="Grid_MouseMove"> <Canvas Name="canvas1"></Canvas> <Button Height="31" Name="button1" Click="button1_Click" Margin="12,12,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="270"> Zoom WAY in to 0,0 and get smooth panning </Button> <Button Height="31" Name="button2" Click="button2_Click" Margin="12,49,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="270"> Zoom WAY in to 200, 200 -- NO smooth panning </Button> </Grid> </Window>
Code for sample:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace TestPanZoom {
wpf transform scale
FTLPhysicsGuy
source share