Yes, that should work, because GridLayout ignores links (i.e. the orange links that appear to connect the groups) and if each Group has its own Layout.
But if you are expecting to allow users to re-order the groups interactively, you should use a custom layout that preserves the current Y position of each node (well, group in your case).
[code] public class VerticalLayout : DiagramLayout {
public override void DoLayout(IEnumerable nodes, IEnumerable links) {
// make sure each node has a Position, defaulting to 0,0
foreach (Node n in nodes) {
if (!n.Visible) continue;
Point pos = n.Position;
if (Double.IsNaN(pos.X)) n.Move(new Point(0, 0), false);
}
// now set their Y positions so that they are all adjacent,
// while setting their X positions to zero
double y = 0;
foreach (Node n in nodes.OrderBy(n => Spot.Center.PointInRect(n.Bounds).Y)) {
if (!n.Visible) continue;
Rect b = n.Bounds;
n.Move(new Point(0, y), true);
y += b.Height;
// for some kinds of nodes you might also want to add some spacing
}
}
}
// This provides visual interactive feedback for where a dragged node will be placed.
// More generally this should use an unbound temporary Node that is defined in XAML,
// rather than hard-coding the definition of the insertion line.
public class VerticalInsertionDraggingTool : DraggingTool {
public override void DoActivate() {
this.InsertionCursor = CreateInsertionCursor();
this.Diagram.PartsModel.AddNode(this.InsertionCursor);
base.DoActivate();
}
public override void DoDeactivate() {
this.Diagram.PartsModel.RemoveNode(this.InsertionCursor);
this.InsertionCursor = null;
base.DoDeactivate();
}
protected Node InsertionCursor { get; set; }
protected Node CreateInsertionCursor() {
Node n = new Node();
n.Id = "InsertionCursor";
n.LayerName = "Tool";
var line = new System.Windows.Shapes.Line();
line.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
line.StrokeThickness = 1;
line.X1 = -1000;
line.Y1 = 0;
line.X2 = +1000;
line.Y2 = 0;
n.Content = line;
return n;
}
protected override void DragOver(Point pt, bool moving, bool copying) {
if (this.InsertionCursor != null) {
double miny = Double.MaxValue;
double maxy = Double.MinValue;
foreach (Node n in this.Diagram.Nodes) {
if (!n.Visible || !n.IsBoundToData) continue;
if (moving && this.DraggedParts != null && this.DraggedParts.ContainsKey(n)) continue;
if (copying && this.CopiedParts != null && this.CopiedParts.ContainsKey(n)) continue;
Rect b = n.Bounds;
miny = Math.Min(miny, b.Y);
maxy = Math.Max(maxy, b.Y+b.Height);
if (b.Y <= pt.Y && pt.Y <= b.Y+b.Height/2) {
this.InsertionCursor.Position = new Point(pt.X, b.Y);
break;
} else if (b.Y+b.Height/2 <= pt.Y && pt.Y <= b.Y+b.Height) {
this.InsertionCursor.Position = new Point(pt.X, b.Y+b.Height);
break;
}
}
if (pt.Y <= miny && miny < Double.MaxValue) {
this.InsertionCursor.Position = new Point(pt.X, miny);
} else if (pt.Y >= maxy && maxy > Double.MinValue) {
this.InsertionCursor.Position = new Point(pt.X, maxy);
}
}
base.DragOver(pt, moving, copying);
}
}[/code]
Install with:
[code]<go:Diagram …>
go:Diagram.Layout
<local:VerticalLayout Conditions=“All” />
</go:Diagram.Layout>
go:Diagram.DraggingTool
<local:VerticalInsertionDraggingTool />
</go:Diagram.DraggingTool>
</go:Diagram>[/code]