Posts: 3
Threads: 1
Joined: Nov 2012
Reputation:
0
I want the correct values for ViewboxMinSize and ViewboxLimits if I want to limit the zoom in and out values to 10% and 500%?
I was not able to figure that out.
Can anybody give me a solution or a hint on how those Viewbox values work together? The examples provided with the Control did not help me a lot.
Hope to hear from you ;-)
Posts: 3
Threads: 1
Joined: Nov 2012
Reputation:
0
Any information on that issue?
Posts: 738
Threads: 8
Joined: Sep 2009
Reputation:
45
This can be done with subscribing to PreviewViewboxChanged event on ZoomPanel and prevent or adjust viewbox changes.
The following method can be used for your case:
private void ZoomPanel1_PreviewViewboxChanged(object sender, Ab2d.Controls.ViewboxChangedRoutedEventArgs e)
{
double zoomFactor = ZoomPanel1.GetZoomFactor(e.NewViewboxValue);
// Limit the zoom in and out values to 10% and 500%
// If outside this limits we will mark the change as handled and this will prevent the change in ZoomPanel
if (zoomFactor < 0.1 || zoomFactor > 5)
{
// First check if we have already limited the zoom in the previous zoom event.
// In this case just prevent on changes done while zooming (this will not prevent only move events)
// Without this the user would still be able to move the content of ZoomPanel when zooming (it looks wrong)
if ((zoomFactor > 5 && e.OldViewboxValue.Width == 0.2) ||
(zoomFactor < 0.1 && e.OldViewboxValue.Width == 10))
{
e.Handled = true; // Prevent any change
}
else
{
// Here we will adjust the NewViewboxValue.Width and NewViewboxValue.Height
// To preserve the location we need to store the new center
double centerX = e.NewViewboxValue.X + e.NewViewboxValue.Width/2;
double centerY = e.NewViewboxValue.Y + e.NewViewboxValue.Height/2;
double newWidth, newHeight;
if (zoomFactor < 0.1)
{
newWidth = 10; // 10% = 10 times the whole content is shown
newHeight = 10;
}
else
{
newWidth = 0.2; // 500% - 1 / 5 of the whole content is shown
newHeight = 0.2;
}
e.NewViewboxValue = new Rect(centerX - newWidth/2, centerY - newHeight/2, newWidth, newHeight);
}
}
}
Andrej Benedik
Posts: 3
Threads: 1
Joined: Nov 2012
Reputation:
0
Hi Andrej,
Great, thanks, that was the solution!
I have not been aware of the PreviewViewboxChanged event as I looked for something like ZoomValueChanged.
Best regards,
Klemens