Drag an Image in the Diagram as Node

I have an application with ToolBars and TreeViews where I can drag and drop items to the diagram.
All works well (thanks for your support Walter).
But now I’m forced to do external drag’n’drop also. The application should be able to show images dragged from the windows-explorer and they should be directly visible as moving nodes in the diagram. So in the CustomDraggingTool I check for e.Data.GetDataPresent(DataFormats.FileDrop) and so on and I’m able to get the Filenames of the dragged files. But now When I call e.Data.SetData(Diagram.Model.DataFromat, dataCollection) with dataCollection holding my new created Nodes I get the “Cannot SetData on a frozen OLE data object.” exception of course.
If I start a drag and drop from the TreeView for example I call the DragDrop.DoDragDrop method - this way the Dragdata is “my” data and I can call SetData on it.
How can I handle this?

I think you’ll need to use a subclass of DraggingTool that overrides the MayAcceptData and AcceptData methods.

Here is a simple example that accepts strings that are dragged in:

  public class StringDraggingTool : DraggingTool {
    public override bool MayAcceptData(IDataObject dataobj) {
      if (dataobj.GetDataPresent(typeof(String))) return true;
      return base.MayAcceptData(dataobj);
    public override IDataCollection AcceptData(IDataObject dataobj) {
      if (dataobj.GetDataPresent(typeof(String))) {
        var coll = this.Diagram.Model.CreateDataCollection();
        String str = dataobj.GetData(typeof(String)) as String;
        if (str != null) {
          coll.AddNode(new TestData() { Name = str, Color="Cyan" });
        return coll;
      } else {
        return base.AcceptData(dataobj);

Hi Walter,
this is not fully working.
If I drag the image I can see a node and can position it on the diagram, but if I drop two images are inserted.
But this I think is my problem. Maybe I have to use an extra DraggingTool. At the moment I have modified my existing DraggingTool.
Is there a way to switch draggingtools depending on what is being dragged?

Thank you.

Regarding switching DraggingTools dynamically – I’m not sure, but I don’t think that makes sense. When events happen, I don’t see how two DraggingTools could operate simultaneously. And if there can only be one operating at a time, I don’t see how the code would know which one to invoke.

I found my mistake!

Thank you.