Custom dragging behavior

I have a WPF GoXam Diagram that sits inside of a legacy WinForms application. (I have a WPF UserControl that contains a GoXam Diagram; the UserControl then sits inside of an ElementHost.) There are other WinForms controls within my app that are valid drop targets so I should be able to drag from my diagram and drop the result onto those controls. The drop behavior is defined differently by each control, but a common format is used within the WinForms DataObject. I see two challenges and could use a little guidance:

  1. Where and when do I create the necessary System.Windows.Forms.DataObject when dragging out of the diagram? (The DataObject will contain a list of the node keys that are participating in the drag.)
  2. How do I retain the built-in GoXam functionality when I’m dragging within the diagram?

I’ve played around with the DraggingTool and it’s not making much sense to me. I overrode DoDragEnter and DoDragLeave (with a simple Debug.WriteLine and then calling the base method) and am seeing far more calls than I expect. For example, dragging a node around in circles with the mouse generates a number of Enter/Leave calls despite the fact that my mouse cursor never leaves or even comes close to the bounds of the GoXam diagram.

I would have expected the leave override to be called only when leaving the Diagram and the enter override only when entering the diagram.

Or am I over thinking this whole thing and it’s as simple as overriding DraggingTool.DoDragDrop to call DragDrop.DoDragDrop with my list of node keys? (But it seems like this would cause the built in functionality to break when dragging within a GoXam digram.) Any pointers you can give me would be appreciated.

Yes, it is what you talk about last – overriding DoDragDrop to add data in whatever formats you need to support.

It is unlikely to cause the standard drag and drop behavior to break, but you can control that by setting the DiagramModel.DataFormat property, if needed.

I’m still playing around with this, but for some reason when my override of DraggingTool.DoDragDrop is called, the Nodes and Links collections of the IDataCollection object are both empty. I suppose I can use DraggingTool.DraggedParts, but it seems weird that the data object which I was passed would be empty.

edit: I’m using GoXam for WPF

That’s odd. I just set a breakpoint in DraggingTool.DoDragDrop and the IDataCollection certainly had the node that I just started to drag in the Palette, and the DataObject passed to DragDrop.DoDragDrop referred to it too.

I’m definitely seeing the other behavior that I mentioned, but I was able to work around the issue via the DraggingTool.DraggedParts dictionary. Here are some possible differences between our scenarios:

  • .NET 4.0 including latest patches from Windows Update
  • Running inside an ElementHost in a WinForms app
  • Part.SelectionElementName set to an object about halfway into my node template

Is your data Serializable?

I’m not sure. If I had to guess, I’d say no due to the ImageSource property that I’m using.