I have a diagram with “ValidUnconnectedLinks = Allowed”. When adding nodes, I can easily set their location by using the GraphLinksModelNodeData.Location property. However, the GraphLinksModelLinkData does not contain any location properties, other than “From” and “To”, which refer to nodes, and “FromPort” and “ToPort”, which refer to ports. In my diagram, some of the nodes have links with “To” set to null. Is it possible to set the location of the end of the link somehow? Right now all these links point to the upper left corner of the diagram, which looks rather messy.
Yes, when one or both ends of a Link do not connect with a Node, you have to either:
- set or bind the Route.Points, or
- overide Route.ComputePoints to handle such cases the way that you want.
If you always want links that are connected at only one end to stick out a short distance from the port, it might be easiest to override Route.ComputePoints to do exactly that, and call the base method otherwise.
Thank you, that did the trick! There was this weird glitch, though. When overriding Route.ComputePoints, I first called base.ComputePoints. Then, if the to-node is null, I created a new list of points, and populated it by using the results of base.ComputePoints, like this:
var ps = this.Points; var firstPoint = ps.First(); this.Points = new List<Point>(); this.Points.Add(firstPoint); this.Points.Add(new Point(firstPoint.X, firstPoint.Y + 100); this.Points.Add(new Point(firstPoint.X, firstPoint.Y + 110);
This worked (except that the links were not centered, until I dragged the node slightly). However, if I removed one of the last two points, or even if I changed them to
this.Points.Add(new Point(firstPoint.X, firstPoint.Y + 10); this.Points.Add(new Point(firstPoint.X, firstPoint.Y + 110);
things looked weird. The links would start at the top of the node (rather than at the bottom, as they should). Also, they would no longer center properly, even when dragging the nodes. Why is this? Have I done anything wrong? And is this related to the fact that in my working solution, the links won’t center until I drag the nodes a little bit?
I’m not sure what your override did, but looking at Route.Points while computing the points might be problematic unless Route.Adjusting is not None.