Override islinkvalid

Hello, i have overrited public override bool IsValidLink(Node pFromnode,FrameworkElement pFromport,Node pTonode,FrameworkElement pToport) in a custom linking tool.

But if there are two nodes to close, the isvalidlink fail ( detect the other node with other restrictions).

Could be possible detect only when the <span id=“result_” =“short_text”="" lang=“en”><span =“hps”="">destination port is selected?

Thank you in advance<span id=“result_” =“short_text”="" lang=“en”><span =“hps”="">

Sure, if pToNode.IsSelected is false, you could return false; otherwise return base.IsValidLink(…).

Hello, i have done that, but does not work, now the select port does not activate.

// Devuelve cierto cuando se puede crear un enlace entre dos elementos, es decir, estamos restringiendo por compatibilidad de nodos, no por si es el enlace correcto o supera el numero de entradas salidas.
public override bool IsValidLink(Node pFromnode, FrameworkElement pFromport, Node pTonode, FrameworkElement pToport)

        BeanResult l_beanResult = new BeanResult(false);
        // Solo comprobamos las condiciones cuando se haya seleccionado el puerto de destino

        // Objeto que nos comprueba las restricciones 
        RtcRestrictions l_restrictions = new RtcRestrictions(pFromnode, pTonode, pFromport, pToport);

        // Comprobamos que el elemento origen y destino sean diferentes
        l_beanResult = l_restrictions.AreDistintToAndFrom(pFromnode, pTonode);

        // Solo si los dos elementos son diferentes compruebo las restricciones
        // En nuestro modelo no puede unirse el mismo elemento mediante un enlace.
        if (l_beanResult.Result == true)
            l_beanResult = l_restrictions.isValidLink();
            if (l_beanResult.Result)
                l_beanResult.Result = base.IsValidLink(pFromnode, pFromport, pTonode, pToport);

        // Si no ha sido seleccionado devuelvo false;
        if (pTonode.IsSelected == false)
            l_beanResult.Result = false;

        return l_beanResult.Result;



I need:

Only when the ToPort is with the pink rectangle, to check the restrictions.


It looks like your current code is returning false unless the topNode selected. If you want to check your additional restrictions only when the toNode is selected, you should return true if the topNode is not selected and return your calculated value otherwise.

Also, if I understand you correctly, you may be checking the wrong node for selection. You are currently checking the toNode, but your previous note makes it sound like you might want to be checking the selection status of the toPort on that Node rather than the Node. If so, you can use FindPort to locate the port’s FrameworkElement, and use Part.FindAncestor to get the node for that port.

No, i need to launch the comprobations, only when the destinity port is selected.

Imagine two elements, one close to other, when i start to create the link, before choose destinity node, the islinkvalid method fire with a destinity element and can be wrong if two elements are so close one to other. I need fire this method ONLY when i know sure, the final node.

IsValidLink is called before the link is made to determine whether or not the potential link makes semantic sense. Returning true from IsValidLink does not create a link, it only makes it possible for a link to be connected to that port. The user may hover over many potential toPorts before releasing the mouse button to create the actual link.

So if you want to want to avoid making a connection between nodes that are too close to each other, you should override IsValidLink to return false if the node locations are too close, and return true otherwise.

If you want to fire some additional code only when you know for sure the final node, you should handle the Diagram LinkDrawnEvent.

Thanks for the answer but i have a question.

The problem is. How know Goxam the ToNode, simply starting a draw a link?. I need to know the final node, before check the isValidLink, because here, i know a final node ( wrong node).

The proposed solution is to leave draw the link, and if it is wrong, remove it, true?.

Thanks for the answer

While you are in the process of drawing a link, GoXam looks for nearby ports that it could connect to. It calls IsValidLink to determine if a link from the current starting port to the nearby ending port would be valid. If so, GoXam snaps the endpoint of the current link to the nearby port. If the user releases the mouse button, that link is created. Otherwise the user can continue to move the mouse and the link being drawn continues to snap to various nearby valid ports until the user releases the mouse button.

So IsValidLink may be called multiple times. Each time it is called, there is a potential Fromnode and Tonode. Each time it is called, you have the opportunity to determine whether or not a link between those 2 nodes would be valid. The final link is created only when IsValidLink returns true and the user releases the mouse button.

Thanks for the answer