我遇到了一些问题,希望有人能回答这个问题。我有一个 Deep Zoom 项目,我使用了标准(deep zoom composer)项目,它在 MultiScaleImage 控件上放置了 DeepZommInitializer 行为。我试图限制拖动以确保用户不会将图像拖出屏幕(因此无法找到图像)。我确实添加了一个主页按钮,它将以 1 的缩放将图像带回起始位置。无论如何,这是我目前拥有的代码(已经在互联网上搜索以寻找答案)。
// msi is the multiscale image
msi.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
{
lastMouseDownPos = e.GetPosition(msi); // class level var
lastMouseViewPort = msi.ViewportOrigin; // class level var
mouseDown = true; // class level var
msi.CaptureMouse();
};
msi.MouseMove += delegate(object sender, MouseEventArgs e)
{
lastMousePos = e.GetPosition(msi);
if (duringDrag)
{
Point newPoint = lastMouseViewPort;
newPoint.X += (lastMouseDownPos.X - lastMousePos.X) / msi.ActualWidth * msi.ViewportWidth;
newPoint.Y += (lastMouseDownPos.Y - lastMousePos.Y) / msi.ActualWidth * msi.ViewportWidth;
var limits = new Rect(new Point(1, 1 / msi.AspectRatio), new Point(-1, -1 / msi.AspectRatio));
if (newPoint.X > limits.Right * .999)
{
newPoint.X += (-2 * (lastMouseDownPos.X - lastMousePos.X)) / msi.ActualWidth * msi.ViewportWidth; // Reverses direction when going off left
}
if (newPoint.Y > limits.Bottom * .999)
{
newPoint.Y += (-2 * (lastMouseDownPos.Y - lastMousePos.Y)) / msi.ActualWidth * msi.ViewportWidth; // Reverses direction when going off top of screen
}
msi.ViewportOrigin = lastMouseViewPort = newPoint;
lastMouseDownPos = lastMousePos;
}
};
我真的需要一个适用于右下角的解决方案,但是当我放大所有值时,所有值都会发生变化。如果缩放级别为 1,我的限制代码有效。我不敢相信这在互联网上无处可寻!但是,当缩放发生变化时,一切都会消失(newPoint 的值不在我期望的范围内)。任何帮助都会很棒!