Port linking question


Let me first explain what it is we’re trying to do. We have two main categories of node, a main node that contains a fixed list (but varies from node to node) of items in an items control and a connector node. The connector nodes represent an item in the list in the main node. We connect up either a main node or connector node to another main node by dragging a link to one of the items in the items list. I have some pictures of this process but I can’t upload them. What we would like to happen at this point, is the selected item in the list is updated with the details of the connector node. Similarly, when a link is deleted, the item in the list should change to “Empty”.

To clarify, the nodes themselves are not set as LinkableTo, instead the list-item data template is. This enables each list-item to be selected independently when drawing the link.

The problem we have is this, even though we give the port an ID in the data template for the list-items, which we could use to determine which list-item was selected. The connected port on the node is always the border of the node. I’m looking in the LinkDrawn event by the way.

Is there a way to determine the port id of the originally selected port that the link was created on?

Apologies if this is a bit confusing.


Do you mean something like this?

private void myDiagram_LinkDrawn(object sender, DiagramEventArgs e) { var link = (Link)e.Part; MessageBox.Show(link.FromPortId); }
Or perhaps I don’t understand what you’re looking for.

That’s exactly what I’m trying to do but for me the port ID is null as it thinks the port it’s attached to is the border element of the node. I’m just playing with some more simple port examples but I’ve effectively done what the documentation suggests.

I think I have it fixed, I was using GraphModel and not GraphLinksModel.

Sorry for the confusion.


While we’re on it though, what’s the best way to detect the deletion of a link?

Just to clarify for any other readers, only GraphLinksModel supports multiple ports on a node.

Regarding detecting link deletion – it depends on the purpose.

The Diagram.SelectionDeleting event might be useful for seeing if any selected Links are deleted by the user.

But I’m guessing that in your situation you’d rather get the DiagramModel.Changed event. That gets called when data is removed from the model for any reason, not just because a Link was selected and the user pressed the Delete key or ^X.

Look for the ModelChangedEventArgs.Change == ModelChange.RemovingLink case. The .Data will be your link data.


I’m looking into a way of removing all existing links from a node when a new link is made. For example connecting a node to a port on another node that is already connected to a node. In this case, I’d like the new link to replace the existing link. I know you can specify a maximum number of links in XAML (go:Node.LinkableMaximum) but I’d like to know if there’s a way in XAML to achieve what I need. If not, I guess it’s achievable in code but can you point me in the right direction (I’m still learning your object model).

Thanks for the help.

If you are talking about a user-drawn new link causing changes to the diagram, then I think you want to handle the Diagram.LinkDrawn event.

You might also care about the Diagram.LinkRelinked event, if you allow relinking.

Remember to perform all changes within a transaction. I recommend trying to implement all of your changes to the model, not by manipulating any Nodes or Links.

Setting go:Node.LinkableMaximum on a port will prevent a user-drawn link (or a user-relinking) from connecting to that port if it would exceed the number. That wouldn’t help with the situation you are describing.

Yep, I’m handling it in the Model.Changed event though, seems to work for me. Was just checking there wasn’t an easier way in XAML.