Binding go:Part.DropOntoBehavior

Hi,

I wanted to the behavior of my drag and drop to be change between AddsLinkFromNode and AddsToGroup. The criteria was as follows:

Drag Type A to Type B:

A B DropOntoBehavior
Group Group AddsLinkFromNode
Group Node not allowed
Node Node not allowed
Node Group AddsToGroup

I added a String DropType to my node data set.

I added a Diagram.DraggingTool and a Diagram.LinkingTool

In my data template, I bound DropOntoBehavior to Data.DropType

I then created override functions :

    public class CustomLinkingTool : LinkingTool
    {
        public override bool IsValidLink(Node fromnode, FrameworkElement fromport, Node tonode, FrameworkElement toport)
        {
            //
            // Handle a group drag n drop onto another group
            //
            if (tonode is Group && fromnode is Group)
            {
                // --> create link
                Node n = fromnode;
                myData md = (myData)n.Data;
                md.DropType = DropOntoBehavior.AddsLinkFromNode.ToString();
            }
            else if (tonode is Node)
            {
                // --> drop into
                Node n = fromnode;
                myData md = (myData)n.Data;
                md.DropType = DropOntoBehavior.AddsToGroup.ToString();
            }
            else
            {
            }

            
            return (true);
            //return base.IsValidLink(fromnode, fromport, tonode, toport);
        }
    }
    public class CustomDraggingTool : DraggingTool
    {
        public override bool IsValidMember(Group group, Node node)
        {
            //
            // Handle a group drag n drop onto another group
            //
            if ((group != null))
            {

                if (node is Group)
                {
                    // --> create link
                    Node n = group;
                    myData md = (myData)n.Data;
                    md.DropType = DropOntoBehavior.AddsLinkFromNode.ToString();
                }
                else if (node is Node)
                {
                    // --> drop into
                    Node n = group;
                    myData md = (myData)n.Data;
                    md.DropType = DropOntoBehavior.AddsToGroup.ToString();
                }
                else
                {
                }

            }

            return (true);

            //return base.IsValidMember(group, node);
        }
    }

My question would be, is this the best way to achieve the functionality described in the logic table above?

Without having thought about it much, it seems to me that having any side-effects in any validity checking predicates is a bad idea.

Instead of adding a DropType data property and binding the DropOntoBehavior property, why not just return true or false as desired from those two predicates?

I would also recommend calling the base method and returning false if it returned false, or just returning what it returns, if you are calling it at the end of the method.

Hmmm, that isn’t sufficient to address the different DropOntoBehaviors for Groups, depending on what is being dropped.

What did you want to happen when the user drags both a Group and a Node (or several of each)?

You can get the most general control by overriding the DraggingTool.ConsiderDragOver and DropOnto methods.

All groups would add links to drop group. (AddsLinkFromNode)
All nodes would add to drop group (AddsToGroup)

my code defiantly fails for multiple selections :( back to the drawling board i guess