How to detect when image is clipped to turn panning on
Similar to previous question ...

I am looking at an 1920x1080 image in a ZoomPanel. I am using mouse and touch.

When the image is completely visible, I want to pin it to center position and prevent mouse/touch panning.

When the image is clipped because of zoom in, I want to allow panning to view otherwise hidden pixels.

I can prevent the panning but I cant seem to figure out when the image is clipping to turn panning on and off at the right moment.

You can check various properties on ZoomPanel to see if you are zooming in or out.

One is ZoomFactor - when it is bigger the 1, then you are zooming in.
The other is Viewbox - when its width and height are smaller than 1, then you are zooming in.

To see examples of the values and some other possible properties check the "ZoomPanelDump" sample under ZoomPanel section.
Andrej Benedik
Thanks for the reply.

When ZoomFactor is 1 the image is not clipped so I can turn off panning completely.

When ZoomFactor is 1.3, the image is clipped at top/bottom but not left/right so I want to allow vertical panning only.

Thats what I am trying to do.

Hi again,

I have been experimenting with your touch sample with the tiger.

Can you please explain the best way to stop the tiger being dragged around when zoomed out. I want it to be in a fixed position until the zoom level requires panning.

When zoomed out it is not very intuitive how to preserve the content of the ZoomPanel centered. To do this you need to first subtract 1 from viewbox.width and height, then divide this by 2 and negate the values - this gives you the correct x and y values for the viewbox.

The following code does the trick (the method handles the PreviewViewboxChanged event):

private void ZoomPanel1_PreviewViewboxChanged(object sender, Ab2d.Controls.ViewboxChangedRoutedEventArgs e)
    if (e.NewViewboxValue.Width > 1 || e.NewViewboxValue.Height > 1) // We are zooming out
        e.NewViewboxValue = new Rect(-(e.NewViewboxValue.Width - 1) / 2, -(e.NewViewboxValue.Height - 1) / 2, // Center the content of ZoomPanel
                                     e.NewViewboxValue.Width, e.NewViewboxValue.Height);                      // Preserve the zoom level
Andrej Benedik

Forum Jump:

Users browsing this thread:
1 Guest(s)