ViewboxLimits
#1
I've been experimenting with the Painter sample. If I check the 'Is Viewbox limited', I get the panning behavior I desired (I can't pan outside normal display bounds with the mini map). 

I won't be allowing mouse wheel on the MiniMap. I only want to limit panning.
I don't really understand what the Viewbox rect represent (I've read and re-read the documentation), but I can't wrap my head around it for some reason.

If I want to allow any zoom, but limit panning, what would I set for the ViewboxLimits and/or ViewboxMinSize?

------

Also, I noticed a bit of a behavior I don't really like with the MiniMap, and don't like, but also unsure how to fix: when zoomed in partially, but not enough where the red box is smaller than the width / height of the actual image, I'm able to pan outside of the bounds (slightly) even when IsViewboxLimited is true.


IE, in the Painter sample, when I'm slightly zoomed in, the vertical bars are enabled, but horizontal bars are disabled (because the content isn't wide enough yet). But even though the horizontal bars are disabled, I can pan left and right. I'd like the content to remain centered (vertically & horizontally), and only allow panning if the appropriate direction scrollbar is enabled / visible.

Here's some screenshots of what I'm trying to describe:
I've zoomed in but haven't panned yet:
   

I panned to the left most edge:
   

I panned to the right most edge:
   

Basically, in the above screenshots, I should be allowed to pan vertically (because the scroll bars are enabled), but not horizontally. Horizontal should remain centered on the content.

I'm also going to have causes where because I'm using StretchAndZoomDirection: DownAndZoom, I will have an image that even when slightly zoomed in will not have vertical or horizontal scrollbars yet, and the panning there should not be allowed to pan in any direction.
#2
There are a few questions, so I will try to answer one after another:

1)
The Viewbox defines a Rectangle in relative coordinates (for 0 to 1). When the Stretch property is set to Fill which allows different scale in x and y direction, then the Viewbox defines exactly what is shown in ZoomPanel. But when the Stretch is set to Uniform (by default), then you may see more then what is defined in Viewbox - the reason for this is that the available area of ZoomPanel can be wider or taller than the content.

To see examples of different Viewbox values please check the samples under ViewboxEx section in the ZoomPanel samples project.


2)
If I want to allow any zoom, but limit panning, what would I set for the ViewboxLimits and/or ViewboxMinSize?

If you want to limit panning, then I would advise to use PreviewViewboxChanged event and there keep the center of rotation fixed (center of rotation is defined by the center of the rectangle defined by Viewbox). 

This can be achieved with the following code:

PHP Code:
       private Point _fixedCenter = new Point(0.50.5);
 
       
        private void ZoomPanel1_PreviewViewboxChanged
(object senderAb2d.Controls.ViewboxChangedRoutedEventArgs e)
 
       {
 
           double newWidth e.NewViewboxValue.Width;
 
           double newHeight e.NewViewboxValue.Height;

 
           e.NewViewboxValue = new Rect(_fixedCenter.newWidth 2_fixedCenter.newHeight 2newWidthnewHeight);
 
       

To test this, use this code in the LimitedZooming.xaml.cs sample in the ZoomPanel samples project.


3)
I am planning to start working on new version of ZoomPanel in the second part of July. I will check what can be done to preserve the content in the center of ZoomPanel in the case that you described. But I cannot promise anything there - currently, the code is actually working correctly - you are not allowed to go past the chosen limit. But I understand that for some users it may be nicer to have the content centered.
Andrej Benedik
#3
Thanks! Your new code got me most of the way there and it fixed ALL of my concerns with a little modification. With your suggested code, panning completely stopped - I was always stuck in the center, even when I should be able to pan up or down (but not left or right). However it was easy enough to modify to get the desired behavior.

Here's what I did to fix it:

1. On the painter sample, on the ScrollViewer, I set the scrollbars for horizontal / vertical to "Auto" for viability.
2. I gave the ScrollViewer a name ("scroll") so I could reference in the code behind.
3. I added two new variables to your suggested code called newX and newY. There values either equal the e.NewViewboxValue.X/Y or the forced center X/Y depending on whether the scrollbars are visible for that direction.

Here's the final code that worked perfectly:
Code:
       private void ZoomPanel1_PreviewViewboxChanged(object sender, Controls.ViewboxChangedRoutedEventArgs e)
       {
           double newWidth = e.NewViewboxValue.Width;
           double newHeight = e.NewViewboxValue.Height;
           double newX = (scroll.ComputedHorizontalScrollBarVisibility == Visibility.Visible) ? e.NewViewboxValue.X : 0.5 - newWidth / 2.0;
           double newY = (scroll.ComputedVerticalScrollBarVisibility == Visibility.Visible) ? e.NewViewboxValue.Y : 0.5 - newWidth / 2.0;

           e.NewViewboxValue = new Rect(newX, newY, newWidth, newHeight);
       }
#4
Great!

Thank you for sharing your final solution.
Andrej Benedik
  


Forum Jump:


Users browsing this thread:
1 Guest(s)