How to take hole diagram to viewerport

Now i use fllow code to implement this(only simple code):

public void BeginUniform(Diagram dia)
{
dia.HorizontalContentAlignment=Stretch;
dia.VerticalContentAlignment=Stretch;
dia.LayoutComplated+=EndUniform;
}
public void EndUniform(obj,e)
{
dia.LayoutComplated-=EndUniform;
dia.HorizontalContentAlignment=None;
dia.VerticalContentAlignment=None;
}
is any better method??

Maybe we should add a DiagramPanel.ZoomToFit method as a convenience.

I haven’t tried this, but it might be implemented as:

public void ZoomToFit() { Rect b = this.DiagramBounds; double xscale = this.ViewportWidth/Math.Max(b.Width, 1); double yscale = this.ViewportHeight/Math.Max(b.Height, 1); this.Scale = Math.Min(xscale, Math.Min(yscale, 1)); }
To be clear, “this” in the above code is a DiagramPanel, the value of Diagram.Panel.