Comparer not always comparing

I have written a custom comparer that uses the incoming port id. This prevents links from crossing each other. There are cases when the comparer event is not firing.

The code is as follows:

<go:Diagram.Layout >
<go:TreeLayout TreeStyle=“LastParents”
Comparer="{StaticResource theFromPortComparer}"
AlternateComparer="{StaticResource theFromPortComparer}" />

public class FromPortComparer : IComparer
public int Compare(TreeVertex x, TreeVertex y)
if (x.Node.NodesInto.Count() > 0 && y.Node.NodesInto.Count() > 0)
List xNodesInto = x.Node.NodesInto.ToList();
List yNodesInto = y.Node.NodesInto.ToList();
if (xNodesInto[0] == yNodesInto[0])
List xLinksInto = x.Node.LinksInto.ToList();
List yLinksInto = y.Node.LinksInto.ToList();
int xLink = int.Parse(xLinksInto[0].FromPortId);
int yLink = int.Parse(yLinksInto[0].FromPortId);
return xLink.CompareTo(yLink);
return 1;

You have set the Sorting property on TreeLayout (i.e. on TreeLayout.RootDefaults), but not the AlternateSorting property (i.e. on TreeLayout.AlternateDefaults).

Hmmm. Since you haven’t set TreeLayout.AlternateAngle, and since for those that you have set “Alternate…” properties they have the same values as the non-“Alternate” properties, I wonder if you want to use the “LastParents” tree style at all. If you want all of the tree vertexes to be laid out in the same way, don’t bother with setting TreeLayout.TreeStyle, leaving it with the default value of “Layered”. Then you don’t need to set any of the “Alternate…” properties.