I'm having some issue and am hoping someone can answer the question. I have a Deep Zoom project that I used the standard (deep zoom composer) project which places a DeepZommInitializer behavior on the MultiScaleImage control. I'm trying to constrain dragging to make sure that the user doesn't drag the image off screen (and therefore is unable to find the image). I did add a Home button which will bring the image back to the starting location at a zoom of 1. Anyway here's the code I currently have (have scoured the internet looking for an answer).
// 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;
}
};
I really need a solution that works for right and bottom but the moment that I zoom at all the values all change. My limit code works if zoom level is 1. I can't believe this is nowhere to be found on the internet! But the moment the zoom changes then everything goes out the window (values for newPoint aren't in the range I expect). Any help would be fantastic!