![]() |
ViewboxLimits and ViewboxMinSize - Printable Version +- AB4D Forum (https://forum.ab4d.com) +-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4) +--- Forum: ZoomPanel (https://forum.ab4d.com/forumdisplay.php?fid=8) +--- Thread: ViewboxLimits and ViewboxMinSize (/showthread.php?tid=3888) |
ViewboxLimits and ViewboxMinSize - kschwarz - 11-29-2012 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 ;-) RE: ViewboxLimits and ViewboxMinSize - kschwarz - 12-04-2012 Any information on that issue? RE: ViewboxLimits and ViewboxMinSize - abenedik - 12-05-2012 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); } } } RE: ViewboxLimits and ViewboxMinSize - kschwarz - 12-05-2012 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 |