Cursor on moving elements in diagram

Hi,

during evaluation of your great library a question occurred for which I could not find an answer in the forums.

Is it possible (and if so, how) to use the DragDropEffects enumeration to change the cursor when moving a node in diagram?

My task:
When moving a node in diagram, the node itself should not be moved and instead a copy of it should be moved. Using a derivation of DraggingTool and overriding IsControlKeyDown, DragOver and DropOnto I am able to do this. For a better user feedback I want to change the cursor using the DrapDropEffecs enumeration (for move / copy / not allowed / etc). Any ideas of how to do this?

Many thanks,
Nick

Are you asking about WPF?

First, I should ask if the DraggingTool.IsRealTime property is sufficient for your needs.

If not, DraggingTool.DoDragOver and DraggingTool.DoDrop set DragEventArgs.Effects in addition to the moving/copying that they do, so I’m wondering if you want to override those methods in addition to or instead of DraggingTool.DragOver and DraggingTool.DropOnto.

Yes, WPF is used.

The DraggingTool.IsRealTime property seems to be sufficient. No need of overriding IsControlKeyDown seems to be required using it.

I tried to override also DraggingTool.DoDragOver but this method is never called.

My DraggingTool Implementation:
public class CustomDraggingTool : DraggingTool<br />{<br /> protected override DragDropEffects DoDragDrop(IDataCollection data, DragDropEffects eff)<br /> {<br /> System.Diagnostics.Trace.WriteLine("DoDragDrop");<br /> return base.DoDragDrop(data, eff);<br /> }<br /><br /> public override void DoDrop(DragEventArgs e)<br /> {<br /> System.Diagnostics.Trace.WriteLine("DoDrop");<br /> base.DoDrop(e);<br /> }<br /><br /> protected override void DragOver(Point pt, bool moving, bool copying)<br /> {<br /> System.Diagnostics.Trace.WriteLine("DragOver");<br /> base.DragOver(pt, moving, copying);<br /> }<br /><br /> protected override void DropOnto(Point pt)<br /> {<br /> System.Diagnostics.Trace.WriteLine("DropOnto");<br /> base.DropOnto(pt);<br /> }<br /><br /> public override void DoActivate()<br /> {<br /> base.DoActivate();<br /> this.IsRealtime = false;<br /> }<br />}

The Diagram:
public MainWindow()<br />{<br /> InitializeComponent();<br /><br /> // Set up an initial model for the Diagram<br /> var model = new GraphLinksModel<GraphLinksModelNodeData<String>, String, String, GraphLinksModelLinkData<String, String>>();<br /> String xml = "<FlowGrammer><NodeData Key='Start' Category='Action' Location='20 20' Text='Start' /><NodeData Key='End' Category='Action' Location='20 150' Text='End' /></FlowGrammer>";<br /><br /> model.Load<GraphLinksModelNodeData<String>, GraphLinksModelLinkData<String, String>>(XElement.Parse(xml), "NodeData", "LinkData");<br /> model.Modifiable = true;<br /><br /> myDiagram.Model = model;<br /> myDiagram.AllowMove = true;<br /> myDiagram.DraggingTool = new CustomDraggingTool();<br />}

Maybe I am missing something, but using this the method DoDragDrop is never called when dragging one node in diagram.

Many thanks,
Nick

I still haven’t seen how you are initializing your Diagram, but I think what is happening is that a drag in the Diagram does not go through Windows drag-and-drop unless you set Diagram.AllowDragOut to be true. The normal behavior is to just handle mouse events. Of course when dragging between controls you need to set Diagram.AllowDrop and/or Diagram.AllowDragOut to be true, but if you really want Windows drag-and-drop entirely within a Diagram you’ll still need to set AllowDragOut = “True”.

By the way, Diagram.AllowMove is true by default.

However, I’m still wondering why you aren’t just setting Diagram.Cursor in your overridden DraggingTool methods (not DoDragOver and DoDragDrop, but DragOver and DropOnto), assuming you do not use Windows drag-and-drop. That’s what some of the tools do.

Setting Diagram.AllowDragOut has the effect that no moving is possible anymore. I guess that further custom implementation is required here by myself.

Nevertheless it looks for me, that doing it with overriding DragOver and DropOnto and changing the cursor inside these methods seems to be appropriate also. Setting the cursor this way has the disadvantage of not being able to use standard move / copy cursor.

Many thanks for your help,
Nick

I am unable to reproduce what you are reporting, that setting Diagram.AllowDragOut to true disables moving. As far as I can tell it works fine, and my override of DraggingTool.DoDragOver is definitely being called. I tried both with DraggingTool.IsRealtime == false as well as true.

But no matter, I think you don’t want to use Windows drag-and-drop anyway. You can use a custom Cursor if you want – that’s something that WPF supports.