Hello,
I am trying to bring into view all elements of a diagram, but cannot manage to fit it to screen. Is there any workaround for BringIntoView method?
I tried to use the followings and won't work.
Last piece of code sometimes works, sometimes doesn't.
Is there a formula to calculate the bounds, the view port size and zoom to fit all elements of a diagram into view?
Thank you!
1.var box = selectedHardwareVariant.Shapes.GetEnclosingBounds();selectedHardwareVariant.DiagramElement.BringIntoView(box, false);selectedHardwareVariant.DiagramElement.Controller.OnViewportChanged();
2.
var box = selectedHardwareVariant.Shapes.GetEnclosingBounds(); selectedHardwareVariant.PanToPosition(box.Center()); selectedHardwareVariant.DiagramElement.BringIntoView(box, false); selectedHardwareVariant.DiagramElement.Controller.OnViewportChanged();3.
Telerik.Windows.Diagrams.Core.DiagramConstants.MinimumZoom = 0.001; Telerik.Windows.Diagrams.Core.DiagramConstants.MaximumZoom = 50; selectedHardwareVariant.AutoScroll = true; selectedHardwareVariant.AutoLayout = true; selectedHardwareVariant.ZoomIn(1); selectedHardwareVariant.Zoom = 1; selectedHardwareVariant.DiagramElement.Controller.OnViewportChanged(); var box = selectedHardwareVariant.Shapes.GetEnclosingBounds(); selectedHardwareVariant.PanToPosition(box.Center()); selectedHardwareVariant.DiagramElement.BringIntoView(box, false); selectedHardwareVariant.DiagramElement.Controller.OnViewportChanged(); IEnumerable<IShape> shapesOutside = selectedHardwareVariant.DiagramElement.Shapes.Where(x => !selectedHardwareVariant.DiagramElement.IsInViewport(x)); for (int i = 0; i < shapesOutside.Count(); i++) { double newZoom = Math.Round(selectedHardwareVariant.Zoom/1.1, 3); box = selectedHardwareVariant.Shapes.GetEnclosingBounds(); selectedHardwareVariant.DiagramElement.PanToPosition(box.Center()); selectedHardwareVariant.DiagramElement.Controller.OnViewportChanged(); selectedHardwareVariant.ZoomOut(newZoom, box.Center()); selectedHardwareVariant.Zoom = newZoom; if (selectedHardwareVariant.DiagramElement.Shapes.All(x => selectedHardwareVariant.DiagramElement.IsInViewport(x))) { break; } }