响应
this question
关于在wpf中缩放和平移,我建议使用scaleTransform并在mousemove事件中更新renderTransform源。这是可行的,但我不高兴的事实是,平移运动不完全匹配鼠标。我知道这个算法有什么问题,但是正确的实现仍然让我难以理解。
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);
}
}