Dynamic Ports - Routing

While trying to implement a tool after the Dynamic Ports sample, I have issues with the Routes:

Links are made from node to node, but not from port to port…
For: Node.GetPortId(port) I get null, because port is always a Grid and not an Rectangle (-> var toport = this.Link.ToPort; and var fromport = this.Link.FromPort; are Grids)

my ListBoxes for the ports are lokking like this:

<util:InertListBox Grid.Column="1" Grid.Row="2"
                 Style="{StaticResource InertListBoxStyle}"
                 ItemsPanel="{StaticResource HorizontalItemsPanel}"
                 ItemsSource="{Binding Path=Data.BottomSockets}">
                                <Rectangle Fill="BlueViolet" Width="8" Height="8" Margin="1 0 1 0"
                         go:Node.PortId="{Binding Name}" Tag="Bottom"
                         go:Node.LinkableFrom="True" go:Node.FromSpot="MiddleBottom">
                                        <TextBlock Text="{Binding Label}" />

I am looking for the issues for days now… Please help me!

Thank you!

My first reaction is that you need to check that your GraphLinksModel’s link data includes both the “FromPort” and the “ToPort” identifiers in addition to the “From” and “To” node identifiers.

If you are using GraphLinksModelLinkData<NodeKey, PortKey>, then the names of those properties happen to be “FromPort” and “ToPort”.

Your node template appears to have ports be Rectangles, because it is those elements that have the go:Node.PortId Binding. So Link.FromPort and Link.ToPort ought to be Rectangles.

If your node DataTemplate is a Grid, then not identifying and finding the specific port element on a given node would explain why Link.ToPort is returning the whole Node rather than a specific Rectangle.

public class DiagramLinkItem : GraphLinksModelLinkData<String, String>, IEquatable<DiagramLinkItem>
public string TypeString { get; set; }
            public object Tag { get; set; }

        public DiagramLinkItem(string _from, string _to, object _tag, string _fromPort, string _toPort)
            Type type = _tag.GetType();
            From = _from;
            To = _to;
            TypeString = type.ToString().Substring(type.GetType().ToString().IndexOf("_") + 1);
            Tag = _tag;
            FromPort = _fromPort;
            ToPort = _toPort;

I also checked if From, To, FromPort and ToPort is set with the debugger. Everything seems to be fine untill it comes to Link.FromPort and Link.ToPort.

And have you checked that the expected port identifiers are actually present on the expected Node? You can call Node.FindPort to see if it actually finds the Rectangle element that you expect.

Node.FindPort returns a Grid :/ , but I do’nt see the difference between my xaml und the xaml from the sample…

I don’t know what to say.

You can recompile and successfully run the Dynamic Ports sample, can’t you?

yes, there are no problems with the sample.

Try iterating over the Node.Ports of a Node. Something like:

    for (var port in aNode.Ports) {

And see if all of the ports have the identifiers you think they should have.

Node.GetPortId(port) returns always null, because the port is a Grid, and the Ports are in the Grid’s InertListBoxes…
So when I try for example Node.GetPortId(((System.Windows.Controls.Grid)portTest).Children[2])) (Giving to GetPortId an InertListBox containing a port), it again returns null, even if there is a port in the Itemssource…

In for (var port in aNode.Ports) each port should be a Rectangle. Is that not the case for you?

no, it returns grids. The rectangles are children of the grid.

Yet your ItemTemplate sets the Node.PortId attached property on the Rectangle. Is that true for all your ItemTemplates? And there is no other use of Node.PortId?

yes, it is set this way for all ItemTemplates, and is never used anywhere else.
And: I have this pattern in my NodeTemplate and in the GroupTemplate again (because my groups can have ports, too).

My data is also from a database and not from xml.

Well, I’m sorry, but I cannot explain the behavior you are seeing with the information that you have given.

I suppose you could try substituting XAML from the sample to see if that works, at the temporary expense of losing whatever else you have implemented.

this doesn’t work, too… there must be something I’ve missed in the code.

But thank you for your efforts!