Set group Layout programatically

How can I progrmatically set Layout for a group in the diagram like it is done on the Diagram in the Table example

myDiagram.Layout = new TableLayout();

I want to set TableLayout for each group in my diagram.

Programmatically you can just set Group.Layout.

But normally one would set it in XAML:

. . .

In either case, of course, you’ll need to make sure your model has all of the nodes be members of the desired groups.

Thanks Walter, but seeting the tableLyout as layout for a group throws following exception “Collection was modified; enumeration operation may not execute.” whereas it works alright for Diagram. Any easy way to fix this?

I have modified the Table sample in GoWpfDemo to display three copies of the original “table”. You can get it from:

I defined a DataTemplate for each Group; this has its Layout be a TableLayout. It also provides a Background brush for the whole group. And it also includes a Canvas, to hold the separator lines set up by each TableLayout.

I set the Diagram.Layout to be a GridLayout, just so the tables would be laid out vertically in a single column.

I changed the model initialization code to add three Items each of which IsSubGraph and to make three copies of the original model data and add them to the new group data.

I also made sure they had unique Key values (prefixed by the group data’s Key) and made sure the link references were also prefixed appropriately. At first I had forgotten to do this, and found that all of the links had disappeared, because there were no longer any nodes with those Keys!

The subtle issue was changing the TableLayout code to make use of the Canvas that each Group has, instead of making a single Node for the whole diagram to hold the Canvas to contain the separator lines.

Thanks Walter, this is exactly what I wanted i.e. a tablelayout for the diagram and the groups.

I see you have set the diagrams layout to Grid and just out of curiosity can grid not be used as a table? I played around a bit with the GLayout example and I could not find a way of explicitly setting the node’s cell (Row,Column)

GridLayout is supposed to position nodes by filling them into a uniform grid.

Real grids don’t have varying size cells.

But if you want to use another TableLayout for the Diagram.Layout, go ahead.