Ports changing in draggable link

I’ve been playing around with the Draggable Link demo and have a question about the behaviour of the ports when a link is present. I am getting two different behaviors depending on how the link is created and I cannot figure out why.

If I modify the LinkSource collection within the DraggableLink constructor so that the link is linked between two objects (as opposed to to being open ended on one end). If I then move one of the two objects around on the diagram the link ports change depending on the orientation of the node being dragged.

However, if I drag and drop from the palette and create the same situation (2 nodes with a link between them), and I do the same behaviour, dragging one node around the other, the link port remains static, it doesn’t change from the one I selected.

What is causing the link ports to change in one situation and not the other? (If I relink the nodes in the first situation above the behavior then matches the second situation). In the program I am working on I prefer the link ports to remain static as in the second situation and therefor am trying to figure out how to stop it from happening. Anyone have any insight?

It depends on which port you connect the link to.

If you try relinking an existing link interactively, you’ll see that the link might connect to any one of four small unseen ports (one in the middle of each side) or to the whole node.

The four ports have PortId values of “L”, “T”, “R”, and “B”. The whole node (actually the NodeShape, which occupies the area of the whole node) has a PortId of “”, the empty string, which is the default value. When you create a link you can specify the string which identifies the port.

But look at the XAML for the NodeTemplate. The four ports have go:Node.FromSpot and go:Node.ToSpot values which tell the links where they should connect at the port. The default port, the NodeShape, does not specify either spot value, and the default is to connect the link at the nearest intersection with the edge of the port. Since the port is a shape, and the shape may have a complex geometry, the end point of the link will follow the edge of the shape.

Thanks. If I hard code the ports I don’t have an issue.

So if I am using the first scenario and I rely on the software to layout my initial diagram, is there any way I can find out what port is being used? (and then force it to be static)

If I look at the Link in OnLinkAdded in my CustomPartManager the link.FromPortId or link.PartsModelFromPortId etc always returns null (not even an empty string).

Actually, maybe I should be asking how to make user defined links be dynamic so the link will always follow the edge of the shape?

I just want consistent behaviour no matter where the diagram originated (dragged in from outside the app (and layout decided by software) or user constructed via the palette)

Thanks again.

Well, that’s a lot simpler – just get rid of all of the FrameworkElements that have a go:Node.PortId specified, other than the one with go:Node.PortId="".

You’ll note that most of the samples are defined that way.

Thank-you for the help, I’ve got everything working consistently now.