ExternalObjectsDropped Cancel or Handled

I have a node in the pallete that can only be dropped onto a group in the diagram.

I want to cancel the drop operation & show a message if user drops this node onto the diagram directly.

How can I achieve this?

I am assuming you are using WPF.

First, make sure that the target diagram has Diagram.AllowDrop set to true.

Second, you need to customize the Diagram.DraggingTool. You’ll want to do something like:

public class CustomDraggingTool : DraggingTool { protected override bool MayCopyExternal(DragEventArgs e) { // check standard cases if (!base.MayCopyExternal(e)) return false; // see if the mouse is over a Group Group overgroup = this.Diagram.Panel.FindElementAt<Group>(this.Diagram.LastMousePointInModel, Part.FindAncestor<Group>, p => true, SearchLayers.Parts); if (overgroup == null) return false; // maybe look at the e.Data to reject additional cases return true; } }
Install this by setting Diagram.DraggingTool, either in code or in XAML:
myDiagram.DraggingTool = new CustomDraggingTool();
<go:Diagram …>
<local:CustomDraggingTool />