Insert Point for Collection of Nodes 2

I have the following problem.
If I drag’n’drop new nodes from a listbox to the diagram the insert point (as we learned in the older thread) tries to calculate the middle point of all inserted nodes.
But in my example he ignores the width and height of the nodes.

As you can see in the images the mouse pointer is on the upper border (ignoring the height) and in the middle of the left side of the most left node and the left side of the most right node (ignoring the width).

In my nodedata I have a width and a height property and these are bound to the width and height of the first element (grid) in the nodetemplate.

Any hint?

Does your node data have location information in them and does your Node template have a data Binding on Node.Location? If the Node.location is not real, the DraggingTool uses some arbitrary offsets from the Diagram.LastMousePointInModel.

The Node.location is bound via multibinding to separate x and y properties of the nodedata.
But I see in Snoop at the moment that the location of the Node-Element is set to n.def., n.def. But the Attached Property Node.Location on the Grid is set.
But it’s the same in the Flowgrammer-Demo. The Location of the node is n.def., n.def. and the Node.Location of the SpotPanel is set to the real values.

By the way this behaviour is nothing I would call arbitrary:

The code path is different for internal drag-and-drop than for external drag-and-drop. The latter path is implemented by:

        Dictionary<Part, Info> copiedparts = new Dictionary<Part, Info>();

          // external drag-and-drop: might be coming from any kind of control
          . . .
          ICopyDictionary dict = model.AddCollectionCopy(data, null);
          // try to be smart about using relative locations of source nodes
          IDataCollection copieddata = dict.Copies;
          IEnumerable<Node> nodes = copieddata.Nodes.Select(d => mgr.FindNodeForData(d, model)).Where(n => n != null);
          foreach (Node n in nodes) {
            // perform bindings in order to get Node.Location values
          Rect bounds = DiagramPanel.ComputeLocations(nodes.Where(n => n.Visibility == Visibility.Visible));
          Point mid = new Point(bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2);
          Point loc = diagram.LastMousePointInModel;
          foreach (Node n in nodes) {
            Point l = n.Location;
            if (Double.IsNaN(l.X) || Double.IsNaN(l.Y)) {  // use artificial locations
              n.Location = loc;
              l = loc;
              loc.X += 20;
              loc.Y += 20;
            } else {
              l.X = loc.X - (mid.X - l.X);
              l.Y = loc.Y - (mid.Y - l.Y);
              n.Location = l;
            copiedparts[n] = new Info() { Point = l };
          foreach (Link l in mgr.FindLinksForData(copieddata)) {
            copiedparts[l] = new Info();

        this.CopiedParts = copiedparts;

I do not understand the hint!
What can I do?

That wasn’t a hint – I was just giving you additional information to help you understand what is happening internally.

Unfortunately this code is hidden within DraggingTool, so it isn’t easily modified – there’s no method that you can override to affect this code’s behavior.

Do you notice a difference if you change the Node.LocationSpot to be Spot.Center?

What are the Node.Bounds of the newly copied Nodes? The behavior you have shown in the screenshots does imply that the Nodes have zero size at the time.

Yes I think the Node.Bounds have zero size. How can I check that? In Snoop I can see the bounds property of the already inserted nodes is set. How can I check the bounds of the floating nodes? My Width and Height Properties are set!

By the way, when I set Node.LocationSpot to Center, the behaviour is as expected - the mouse pointer is in the center of the collection. So he must have the correct bounds on the node anyway! Why it doesn’t work with LocationSpot default?

But I can’t use Node.LocationSpot = Center, cause I must have my X and Y on the TopLeft-Position of my nodes.

So, why does the DraggingTool appears to respect the height and width when LocationSpot is set to Center and ignores them when set to TopLeft?

I don’t know at this time. I’m going to have to create a test case so that I can debug it.

This will be resolved by a new method DraggingTool.ComputeFocusPoint in version 2.2.

Coming soon…