Understanding groups

I am having trouble understanding the concept of groups fully. In my mind a group is just a node that may have other nodes as children. However, I have not been able to achieve a diagram containing a node that is a group without children.

For example, in the Navigator sample of the GoWpfDemo3 solution, if I comment out the leaf node E in the Navigator.xml file the parent Phi node disappears too. I would have expected an empty Phi node to be shown - after all its GroupTemplate specifies a Border, a TextBlock and some Padding that should be rendered.

And you should expect that. But unfortunately there is a bug in the Navigator sample. (Thanks for pointing it out!)

A Group that includes a GroupPanel will surround itself around its member nodes. If there are no member nodes, it’s Location stays unchanged, although its Width and Height shrink down to its Padding margins.

The bug is that the DataTemplate (“GroupTemplate”) forgot to include the same data-binding that the “NodeTemplate” used, on the outer Border:

    go:Node.Location="{Binding Path=Data.InitPosition}"

Without this binding there’s no way for it to get an initial Location from the data, which was specified in the XML and loaded into memory:

    <n name="Phi" subGraph="Psi" isSubGraph="True" x="410" y="220" />

Thanks, that makes sense now, but is there an easy way to ensure that the GroupPanel surrounds the remaining TextBlock, or does the panel width calculation just concern itself with the child nodes?

For example, continuing with my example of the leaf node E being commented out, the Phi text extends beyond its parent border.

Sure – it’s just XAML, so you can change it around as much as you like.

For example, replace the content of the Border with:

<StackPanel> <TextBlock Name="TextBlock" Text="{Binding Path=Data.Key}" FontSize="12" FontWeight="Bold" Margin="5 0 5 0" Foreground="{Binding Path=Data.Highlight, Converter={StaticResource theColorConverter}}"/> <go:GroupPanel x:Name="myGroupPanel" Padding="5" /> </StackPanel>