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:
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”.
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?
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()
{
InitializeComponent();
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;
}
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;
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.