Limit zoom factor


Is it possible to prevent zooming out further as soon as zoom-to-fit level is reached? If so, how? If not, how can I catch zoom and scroll events?

I suppose you could override CommandHandler.CanDecreaseZoom when the DiagramPanel.ViewportBounds is larger than the DiagramPanel.DiagramBounds.

Or something like that.

On second thought, I’d rather prefer catching zoom and scroll events. How could I do that?

You can use DiagramPanel.MaximumScale and DiagramPanel.MinimumScale to control how far the user zooms.

Those properties can also be set in various event handlers so that it can adapt to the size of your diagram contents and the size of the viewport and whatever else you care about.

But which event is thrown when the user scrolls or zooms?

I’m recommending that you avoid the situation where the user has already changed the DiagramPanel.Position or DiagramPanel.Scale and you want to change it back.

I think it’s better to avoid letting them go too far in the first place.

Oh, scrolling limits are determined by the DiagramPanel.DiagramBounds.

That’s a misunderstanding. I don’t actually want to limit the zoom factor. What I actually want to do is adjust a node’s width (and its width only, the height is supposed to zoom and scroll normally) to always fit the viewport width (and horizontal position). I got this to work upon changing the viewport’s size but not on a simple scroll or zoom as I don’t know which event to bind to.

Limiting the zoom factor is actually just a fallback in which I set the width of the proper nodes to either the initial viewport width or the width of the diagram bounds, whichever is larger, and then not letting the user zoom out further so said nodes are always visible across the whole horizontal width of the viewport.

I’d prefer the first case, however.

You used the DiagramPanel.ViewportBoundsChanged and DiagramPanel.DiagramBoundsChanged events?

Did you want to disable horizontal scrolling? Set this to false:

I actually used the SizeChanged event. Changed it now to ViewportBoundsChanged event and now it basically works. There are two issues, though.

First, it seems the ViewportBounds.Width is incorrect when zooming out. See the picture.

Second, only Nodes other than those background nodes you can see in the picture are supposed to define the DiagramBounds. However, as the diagram is initialized with a viewport width of 1707 and thus, background nodes are drawn with the same width, DiagramBounds.Width is also set to 1707. Now, when I zoom in, background nodes decrease their width according to the viewport, but the DiagramBounds stay like they are, even though they should decrease as well. Can I tell the diagram to ignore the background nodes when it calculates the DiagramBounds? Or do I have to manually refresh the DiagramBounds if the background nodes’ width has changed? How would I do that?

You can set/bind the Part.InDiagramBounds property to control whether or not the Part (probably only Nodes in your case) is considered by DiagramPanel.ComputeDiagramBounds.

Another possibility is to set DiagramPanel.FixedBounds as a way for you to control the value of DiagramPanel.DiagramBounds.