Silverlight does not support drag-and-drop between controls. We have implemented our own mechanism for that, but it is not as extensible as the drag-and-drop support in WPF.
So instead of preventing nodes from being created when data is dropped, the best you can do is to cancel the dragging operation if you don’t want the dropped nodes to remain.
[code] public class CustomDraggingTool : DraggingTool {
// don’t allow dropping onto a Node
// whose Data.Key contains the letter ‘e’
public bool IsOK(Node node) {
if (node == null) return true;
var data = node.Data as TestPageData;
if (data == null) return true;
return !data.Key.Contains(‘e’);
}
protected override void DragOver(Point pt, bool moving, bool copying) {
// if dragging from a different Diagram
if (DraggingTool.Source != this) {
// don't consider nodes that are selected, being dragged
Node over = this.Diagram.Panel.FindElementAt<Node>(pt,
Part.FindAncestor<Node>,
p => !this.Diagram.SelectedParts.Contains(p),
SearchLayers.Nodes);
// if it's not OK to drop here, just change the cursor
if (!IsOK(over)) {
DraggingTool.Source.Diagram.Cursor = Cursors.None;
return;
}
DraggingTool.Source.Diagram.Cursor = Cursors.Arrow;
}
base.DragOver(pt, moving, copying);
}
protected override void DropOnto(Point pt) {
// if dragging from a different Diagram
if (DraggingTool.Source != this) {
// don't consider nodes that are selected, being dragged
Node over = this.Diagram.Panel.FindElementAt<Node>(pt,
Part.FindAncestor<Node>,
p => !this.Diagram.SelectedParts.Contains(p),
SearchLayers.Nodes);
// if it's not OK to drop here, cancel the drop
if (!IsOK(over)) {
DoCancel();
return;
}
}
base.DropOnto(pt);
}
}[/code]
Install this custom DraggingTool by setting your Diagram.DraggingTool, either in code or in XAML:
myDiagram.DraggingTool = new CustomDraggingTool();
or:
<go:Diagram …>
go:Diagram.DraggingTool
<local:CustomDraggingTool />
</go:Diagram.DraggingTool>
</go:Diagram>
Of course you’ll want to adapt the “IsOK” predicate to be suitable for your application. And you may need to customize the code some more if your decision about whether it’s OK to drop includes dropping onto links or onto the background.
Thank you walter !!!