How can I zoom in the selectionPart?

How can I zoom in when I select part of the graph?
Everytime I select the part of the graph,it just highlight the nodes and links in the selectionPart.But I also want to zoom in the selectionPart? How can I do this?
Can anyone help me ?
Following is the illustration:
actual effect:

ideal effect:

I suggest that you call the code that is shown in the documentation for DiagramPanel.CenterRect:

myDiagram.Panel.CenterRect(myDiagram.Panel.ComputeBounds(myDiagram.SelectedParts), null);

Thx,Mr.walter,I tried your way,but it just centered the the selection in the viewport,I aslo want to let it zoom in,I mean make the selection fill the viewport.How can I do this ?

Ah, right – I forgot about that bit. I have not even tried compiling this, but maybe something like:

  void ZoomTo(Diagram diagram, Rect bounds) {
    var panel = diagram.Panel;
    double xscale = panel.ViewportWidth / Math.Max(bounds.Width, 1);
    double yscale = panel.ViewportHeight / Math.Max(bounds.Height, 1);
    if (panel.ScrollOwner != null) {
      ScrollViewer sv = this.ScrollOwner;
      Thickness pad = sv.Padding;
      Thickness brd = sv.BorderThickness;
      if (sv.HorizontalScrollBarVisibility != ScrollBarVisibility.Visible) {
        double w = sv.ActualWidth - pad.Left - pad.Right - brd.Left - brd.Right;
        xscale = w / Math.Max(bounds.Width, 1);
      }
      if (sv.VerticalScrollBarVisibility != ScrollBarVisibility.Visible) {
        double h = sv.ActualHeight - pad.Top - pad.Bottom - brd.Top - brd.Bottom;
        yscale = h / Math.Max(bounds.Height, 1);
      }
    }
    xscale = Math.Max(0.001, Math.Min(xscale, 1));
    yscale = Math.Max(0.001, Math.Min(yscale, 1));
    panel.Scale = Math.Min(xscale, yscale);
    panel.CenterRect(bounds, null);
  }

What is the “ScrollViewer sv=this.SrollOwner”,it met error.

I change “this” with panel,and it work!
Thanks very much! Mr.Walter:grinning: