In response to this question about zooming and panning in WPF I made the suggestion to use a ScaleTransform and update the RenderTransform origin in the MouseMove event. This works but I'm not happy with the fact that the panning movement does not quite match the mouse. I can see what the problem with this algorithm is, but the correct implementation continues to elude me.
private void image_MouseMove(object sender, MouseEventArgs e)
{
if (image.IsMouseCaptured)
{
Vector v = start - e.GetPosition(image);
// this calculates the deltas relative to the original size of the image
// but does not take into account the transformed size, but transforming the
// size like image.ActualWidth * scaleTransform.ScaleX does not help
double deltax = v.X / image.ActualWidth;
double deltay = v.Y / image.ActualHeight;
image.RenderTransformOrigin = new Point(orgin.X + deltax, orgin.Y + deltay);
}
}
Any ideas on how I can make this approach work?