How to detect when image is clipped to turn panning on
#5
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):

Code:
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
  


Messages In This Thread
RE: How to detect when image is clipped to turn panning on - by abenedik - 08-26-2019, 09:24 AM

Forum Jump:


Users browsing this thread:
1 Guest(s)