Node moving to the top left corner during Drag & Drop

I’ve got a diagram configured with :
NodeTemplateDictionary="{StaticResource NodeTemplateDictionary}"
GroupTemplate="{StaticResource MyGroupTemplate}"
AllowZoom =“True”

I’m using Group containing one or more Nodes. Those Nodes contains themselves 2 lists of sub-Nodes.
I’m also using 2 dictionaries for Drag & Drop.
You can add a Node inside a Group, or inside a new group (automatically created)
Sub node must be added inside an existing Node.
When I’m dragging a Node from Node’s dictionary to the diagram, current view is automatically moved to the top/left (If it doesn’t occurs, I only have to leave the diagram with Drag & Drop still activated to make view move to the top/left).
But when I’m dragging a sub-Node, then Diagram doesn’t move.
I’ve checked values for HorizontalContentAlignment and VerticalContentAlignment during Drag and Drop, and they are equals to those I’ve configured.
Do you have any idea ?

Some small screenshots would help describe the situation.

What is your Diagram.Layout?

Does it happen the second time you do it?

Hi Walter,

I’m using my Own Diagram (based on DiagramLayout) to override DoLayout.
I made you a copy screen before starting Drag & Drop, and during Drag & Drop

As you can see during Drag & Drop group is moved automatically to the top/left.

And the behavior is repeatable with a second or third drag-and-drop?

Yes, after a Drag & Drop if I move diagram position and restart a Drag & Drop Group is moved to the top/left again.
I’ve made a test by exchanging my Diagram layout with a predefined layout (CircularLayout) and the behavior is reproducible, but I’ve following exception:

System.InvalidOperationException: ‘‘System.Windows.Media.Animation.PointAnimation’ cannot use default destination value of ‘NaN,NaN’.’

I assume two of those are typos only in this forum post. And not setting them makes no difference.

I don’t understand why the behavior in your app is different from that in the Basic demo or in the various samples in GoWpfDemo that make use of a Palette.

Hi Walter,

It seems that my problem may have something to deal with AdornerLayer.

Got it,
I’ve got a dummy Group use to create/add a new Group. This dummy group is visible only when Drag & Drop has been initiated.
To hide this group I switch dynamically, during Drag & Drop, the main Border Visibility between Visibility.Visible and Visibility.collapsed.
This dynamic changes is the reason why nodes moved.

Do you understand :

  • Why all nodes are moved and why always to the top/left?
  • Why is diagram’s HorizontalContentAlignment attribute is in this case ignored?

I assume your Group template includes a Placeholder. The Placeholder’s area is always the union of the areas occupied by the group’s members. So if there is only one Node in the Group, the Placeholder is only just big enough to hold the Node. Depending on how the Placeholder is aligned within the Group’s Panels, that determines where the member Node(s) will be relative to the other elements of the Group.

Would it help to set the Border’s Visibility to Hidden instead of Collapsed?

I’ve already modified my code to use Hidden rather than Collapsed.

So it’s now behaving the way you expected?

Yes and No.

If I allow scrolling during Drag & Drop and move to the View border, then Diagram is moved until it reached the border and then it “jump” to the top/left. When I release Drag & Drop diagram turn back to the middle of the screen according to HorizontalContentAlignment

I’ve made you a short video.

Which kind of event initiate this “jump”, and why top/left?

That behavior is called autoscrolling. It is caused by the dragging mouse point being just inside the edge of the Diagram element. The closer to the edge the mouse is, the faster it goes.

There are DiagramPanel properties that control autoscrolling behavior. If you do not want your users to autoscroll at all, you can disable it by setting to a zero Thickness. Or maybe you want to increase AutoScrollDelay, although that will make intentional autoscrolling more difficult.

Hi Walter,

I think I understood why my nodes are no longer centralized.
During the Drag & Drop operation, when crossing the diagram limits or during the scrolling operation, they become invalid (NaN).
Do you have any idea why?

I assume it is the Node.Location that has NaN values, yes?

Well it should be expected that newly created nodes do not yet have valid locations until they get assigned either by your code or by layout. For groups that have a placeholder, that only happens until they have been measured and arranged. Does your dummy group have a Group.Layout, and does it have a member node that has a real Bounds? Perhaps you should be assigning the group’s position.

Oups sorry,
it looks like that I’ve forgotten something in my previously text. Whats became invalid is the Diagram.Panel.DiagramBounds.BottomRight.X and Y values.

When parts are added, the DiagramBounds are invalidated. Eventually the parts are measured and arranged, and then the DiagramBounds are computed again. Try calling