Group Templates - help?

I have a group template defined.

If I drop a node into the group - the position of the group within the diagram changes.

What I'm trying to do is to create a container group that I can drop nodes into. Ideally I would like the node to maintain the existing position and size.

My group template is defined as ...



My diagram is defined as 


I also have a custom dragging tool ...

   protected override void DropOnto(Point pt)
            Part top = this.Diagram.Panel.FindElementsAt(pt,
                              p => !this.Diagram.SelectedParts.Contains(p),

            Group group = top as Group;

            if (Diagram.SelectedNode != null && Diagram.SelectedNode.Data != null)
                MyNodeData g = Diagram.SelectedNode.Data as MyNodeData;

                if (g != null)
                    if (group != null)
                        g.SubGraphKey = ((MyNodeData)group.Data).Key;
                        g.SubGraphKey = null;


I know it'll be something simple and have tried to simplify my model - but can't seem to get it to work.

Can anyone please help?

If you are using a GroupPanel, that panel automatically takes the size and position needed to exactly cover the area of its member nodes and links plus some padding.

It sounds like you don’t want the container to change size or position as member nodes get added or removed. If so, I suggest you not use a GroupPanel at all in your Group’s DataTemplate.

Take a look at the Planogram sample – the “Rack” template uses a Border-ed GridPattern instead of a GroupPanel, but you could just use a Rectangle.

Note also how it sets go:Part.DropOntoBehavior=“AddsToGroup” and sets go:DraggingTool.DropOntoEnabled=“True”. I suspect you don’t need to override the DropOnto method at all, at least for the common & simple cases.

It’s simple when you know how!

Thanks. Sorted.

When I say it’s sorted …

I’ve been experimenting with the planogram templates, and I still can’t get it to do quite what I want …

I would like a Group that contains a set of parts. I want to use a Grid layout to arrange the parts as they are dropped into the group. I would like the Group template surround all of the layed out parts.

  1. I can’t get the group template to surround the parts. Even if I use a GroupPanel it does some of what I want, but it does tend to drift in the y-axis as I add components to it.
  2. The GridLayout’s WrappingWidth does not seem to adapt to the Group containers width. Perhaps I need to bind to it?

Assuming that I can get this to work - my next task is to enable the re-ordering of the contained parts by dragging them to the new position. I’ll worry about this when I’ve achieved the “simpler” solution.

Any assistance and/or pointers would be great.

Part of the problem is that my mindset is not quite aligned with Silverlight and I tend to think the more traditional WinForms patterns. When it clicks in my mind, I know that I’ll wonder what all the fuss was about!



Ah ha …

Binding the layout’s WrappingWidth to the width of the Group and then using Alignment=“Position” resolved my problem.

Actually, I’m not sure that it does, because the ActualWidth of the Group depends on the ActualWidth of its GroupPanel, and the GroupPanel’s width is determined by the layout of the member nodes. So there’s a circular dependency there. I suppose it settles down quickly because the nodes are all wide enough for the granularity of the GroupPanel width to be large enough to avoid an indeterminate number of re-layouts.

But you still have a problem with your next task – to reorder the member nodes upon drag-and-drop. I’m not sure what the best solution is.

One possibility is to customize the DraggingTool to recognize when one or member nodes have been moved (or copied?), change the ordering of the nodes, and invalidate the GridLayout.

I’ve not actualy used a GroupPanel to test it. At the moment I’m using a . I was going to tes tit with a GroupPanel - and had wondered about circular references.

I’m not sure if this is possbile but I would imaging that there are 2 places where, in theory, I could override the base functionality …

  1. GridLayout.DoLayout

Could I override this, calling the base.DoLayout. I can then loop though each of the layed out nodes to calculate the bottom-most node - and then set the Group’s height.

  1. Create my own Panel.

I’m not sure about how to go about this, but I’m hoping that there will be a mechanism that will enable me to trap a call to layout?

Oh, OK, I had assumed you were using a GroupPanel again. Sorry.

Yes, overriding DoLayout would make sense. To get the actual height you might find it easier to call DiagramPanel.ComputeBounds on the argument collection of Nodes.