Hi Stoyan,
To perform zooming from the center of the diagram, we have used following code.
public void SetZoom(double percentage)
{
try
{
diagram.ZoomToFit();
if (percentage > 200)
{
percentage = 200;
}
else if (percentage < 10)
{
percentage = 10;
}
ScrollViewer scrollViewer = diagram.Parent as ScrollViewer;
Point oldCenter = diagram.ClientToDoc(new Point(scrollViewer.ViewportWidth / 2, scrollViewer.ViewportHeight / 2));
double newScrollX = diagram.ScrollX;
double newScrollY = diagram.ScrollY;
diagram.ZoomFactor = percentage;
Rect newBounds = diagram.ClientToDoc(new Rect(0, 0, scrollViewer.ViewportWidth, scrollViewer.ViewportHeight));
Point newCenter = diagram.ClientToDoc(new Point(scrollViewer.ViewportWidth / 2, scrollViewer.ViewportHeight / 2));
double diffx = (oldCenter.X - newCenter.X);
double diffy = (oldCenter.Y - newCenter.Y);
newScrollX += diffx;
newScrollY += diffy;
newBounds.X = newScrollX;
newBounds.Y = newScrollY;
newBounds.Union(diagram.GetContentBounds(false, false));
newBounds.Inflate(200, 200);
diagram.Bounds = newBounds;
diagram.ScrollTo(new Point(newScrollX, newScrollY));
}
catch (Exception ex)
{
Debug.WriteLine("Exception in SetZoom : " + ex.Message);
}
}
Problem:After zoom when we try to drag the node at extreme right of the diagram, horizontal bar position get change. Now if we zoom again it performs zooming from the diagram center, so in this case we get a different view during zooming from the view on which we were doing some work.
Requirement:We want zooming should perform from the center of the visible client area. Client area which is viewable should have zooming center.
Please suggest how can we achieve this? ???
Regards,
Anshul