Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Drag and drop onto Diagram (Read 321 times)
Joel D.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 40
Location: Seattle
Joined: Feb 6th, 2017
Drag and drop onto Diagram
Jun 20th, 2024 at 6:34pm
Print Post  
In my project, users drag and drop TemplatedNodes from an ItemsControl, which I initiate by calling these lines of code:
var dn = new DraggedNode() { Node = node };
DragDrop.DoDragDrop(this, dn, DragDropEffects.Copy);


In Diagramming 3.5, the user would drop the node on the Diagram, and in the NodeCreated event I would see e.Node.Bounds.TopLeft would be set to where the mouse was when the node was dropped.
But now in Diagramming 4.1, e.Node.Bounds.TopLeft is always [0,0] regardless of where the mouse pointer is.

Also, in Diagramming 4.1, there is now a drag adorner that follows the mouse pointer around. Is there a way to either disable the adorner, or perhaps is there an event I can handle that lets me draw the adorner myself?

Thanks!
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3262
Joined: Oct 19th, 2005
Re: Drag and drop onto Diagram
Reply #1 - Jun 21st, 2024 at 8:22am
Print Post  
NodeCreated is raised only after the dropped node is placed at mouse location, so you shouldn't be seeing 0,0 reported as coordinates if the new node appears where you expect it to. Maybe check if you aren't looking at DraggedNode.Node.Bounds instead. Also note that new HorizontalDropAlignment and VerticalDropAlignment properties could add some offset from mouse pointer to node if you set them to non-default values.

Set DragIndicatorOpacity = 0 to remove that drag adorner. There won't be an invisible adorner dragged around then, the visual is created only for non-zero opacity.

The drag indicator is a clone of the dragged node actually, so you might be able to show a different representation by rendering a different template when Parent is null.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Joel D.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 40
Location: Seattle
Joined: Feb 6th, 2017
Re: Drag and drop onto Diagram
Reply #2 - Jun 21st, 2024 at 9:53pm
Print Post  
I don't think I have access to DraggedNode in the NodeCreated event handler, as the Drop event is handled by the internal Diagram code.

I dug into your source code though, and I realized I had to change the DraggedNode I pass in to DoDragDrop to:
var dn = new DraggedNode() { Node = node, Size = node.Bounds.Size };
because the OnDrop code in Diagram.cs won't assign the cloned node's Bounds unless the passed in Size is greater than zero.

Regarding the drag adorner: if I'm in the middle of drag-and-dropping a new node over the diagram and I happen to mouse over a node that is already on the diagram, OnTemplateChanged continually gets called as the mouse is over the existing node. And perhaps my templates are quite complex, because the rendering of the drag adorner hiccups and the adorner will flash or pause.  But perhaps I'll try what you suggested of showing a different template when Parent is null, and keep that template super simple.

Thanks!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint