Hi!
I’m trying to use LinkingTool to detect the linking connections between the nodes but something goes wrong when i connect the nodes. The scenario is: 2 input nodes (node 1 and node 2) and 2 output nodes (node 3 and node 4). When i connect the input node 1 to output node 3 the IsValidLink event is fired 2 times, as i have connected the input node 1 to output node 3 and also to output node 4). What could be wrong with the IsValidLink event? Thanks for your support
My code:
public class MyCustomLinkTool : LinkingTool
{
public override bool IsValidLink(Node <b>fromNode</b>, FrameworkElement fromPort, Node <b>toNode</b>, FrameworkElement toPort)
{
if (!base.IsValidLink(fromNode, fromPort, toNode, toPort)) return false;
BaseNodeData fromNodeData = fromNode.Data as BaseNodeData;
BaseNodeData toNodeData = toNode.Data as BaseNodeData;
//NOTE: The inputs array begins with the index 0
// The outputs array beginswith the index 500
int fromPortIndex = Convert.ToInt32(fromNode.GetPortName(fromPort)) - 500;
int toPortIndex = Convert.ToInt32(toNode.GetPortName(toPort));
//Check if the connected ports are of the same type and if the INPUTS ports connects with //the OUTPUTS ports
if (fromNodeData.InputsIOTag[fromPortIndex].GetType() == toNodeData.OutputsIOTag[toPortIndex].GetType())
{
Console.WriteLine("CONNECT LinkingTool: " + " From =" + fromNodeData.Key + " To = " + toNodeData.Key + " FromPort = " + fromPortIndex + " ToPort = " + toPortIndex + " Is linked = " + base.IsValidFrom(fromNode, fromPort));
}
else
return false;
return true;
}