Customize links created via dragging


Thank you in advance for your help!

My model has the following link flow:

           <-- Operand-1

Operator <-- Operand-2
<-- …

For domain-specific reasons the above Operator node can accept more Operand inputs, but needs at least 2. So I created the below rectangle input on Operator to allow the user to drag out more links and I marked the 2 initial links as not deleteable:

<Rectangle go:Node.PortId=“Input1” go:Node.LinkableFrom=“True” …/>).

However, by default dragging the new link out sets the Operator as the FROM node and the Operator as the TO node (which is backwards for my case). How can I customize the creation of this new link? If I put a breakpoint in my custom Link class constructor the call stack shows the call as immediately coming from “external code”.


If it’s an “input”, wouldn’t you want to say go:Node.LinkableTo=“True”?

Not really. Wink

In this model no one can drag a link into a TO node’s input. Instead, the TO node allows you to drag a link from itself to the FROM node. The problem I’m having is that I’m not sure how I can enforce this domain-specific requirement. Is there anyway I can customize the link creation code when a FROM --> TO link is established immediately after the user drags out a new link such that the meaning is that the FROM is really the TO and vice-versa?

Maybe you just need to set DraggingTool.Direction.

I don’t see Direction as an option here:

How do I set that?

Oops – sorry about that typo: I meant LinkingTool.Direction.

Thank you for your quick response! Smile

I tried all 3 options for LinkingDirection (ForwardsOnly, BackwardsOnly, Either). Unfortunately I didn’t get the desired behavior.

Below I’ve created what I think is close to a minimum-working example to illustrate what I’ve got and the desired use-case. When run, this is the image I initially get when I try to create a link from Operand-2 to Operator by clicking and dragging out FROM Operator’s lower-left rectangle (highlighted in pink).

After I create that link, this is what I get, so the new link is just backwards (for this use-case). Operand-2 should be flowing into Operator, not vice-versa.

I realize this isn’t a typical use-case, and overriding certain methods of the LinkingTool might be appropriate, I just couldn’t figure that out on my own. I saw documentation for overriding link validation, but not link-creation.

Here is the code-behind:

public MainWindow()
diagram.Model = new GraphLinksModel<GraphLinksModelNodeData, String, String, GraphLinksModelLinkData<string, string>>
Modifiable = true,
NodesSource = new List<GraphLinksModelNodeData>()
new GraphLinksModelNodeData(){Text=“Operator”, Key=“Operator”, Category=“OperatorRenderKey”},
new GraphLinksModelNodeData(){Text=“Operand-1”, Key=“Operand-1”, Category=“OperatorRenderKey”},
new GraphLinksModelNodeData(){Text=“Operand-2”, Key=“Operand-2”, Category=“OperatorRenderKey”}
LinksSource = new List<GraphLinksModelLinkData<string, string>>()
new GraphLinksModelLinkData<string, string>(){From=“Operand-1”, FromPort=“Output”, To=“Operator”, ToPort = “Input2”}
//diagram.LinkingTool.Direction = Northwoods.GoXam.Tool.LinkingDirection.ForwardsOnly;

And here is the XAML:

<go:NodePanel Cursor=“Hand” Sizing=“Auto”>
<go:NodeShape Opacity=“1” Stroke=“Pink” StrokeThickness=“1” go:NodePanel.Figure=“StopSign”/>






What if I subclass LinkingTool and override the #DoMouseUp method, so that the link that gets created is backwards?

public override void DoMouseUp()
var swapMeNode = base.OriginalFromNode;
var swapMePort = base.OriginalFromPort;
base.OriginalFromNode = base.OriginalToNode;
base.OriginalFromPort = base.OriginalToPort;
base.OriginalToNode = swapMeNode;
base.OriginalFromPort = swapMePort;

Did you try my original suggestion?

Yup. I should’ve been more clear above, I said that I “tried all 3 options for LinkingDirection (ForwardsOnly, BackwardsOnly, Either). Unfortunately I didn’t get the desired behavior.” That should have read I tried all 3 options for LinkingTool.Direction. I did that in the commented out line of MainWindow.cs above:
//diagram.LinkingTool.Direction = Northwoods.GoXam.Tool.LinkingDirection.ForwardsOnly;

No, my original suggestion did not involve LinkingTool.Direction.

I suggested setting go:Node.LinkableTo=“true” on all input ports and go:Node.LinkableFrom=“true” on all output ports.

Wow, I was making that way more complicated than it was. I think that works. Thanks!

I have one quick question that’s probably not worthy of its own post: If I make a link not deleteable (go:Part.Deletable=“False”) but the node that it links from is deleteable, how do I prevent the link from being deleted if the user selects the linked-from node and hits the delete key? Do I have to override CommandHandler#Delete? I would want to leave a dangling link-behind in this case, and only delete the link if it has no TO node.