Link.Route is not updated immediately in ModelChanged


I am subscribing to ModelChanged method and when the change is ModelChange.CommittedTransaction I track the transaction from the code below:

var edits = (e?.OldValue as UndoManager.CompoundEdit).Edits.Select(edit => edit as ModelChangedEventArgs).ToList();

and when the change is ModelChange.AddedLink I get the Link using PartManager.FindLinkForData().
Now when I access Route.Points I get just the default values.

What I expect is that it should return me the actual route values. Rather I get default values which causing problem for my further code.

Also what I have observed is that in the debug mode these values are updated after some time.

That is correct – Link routes are actually computed later, after the connected Nodes have been measured and arranged and positioned by any layout. This all happens towards the end of a transaction.

What is it that you are trying to accomplish?

But I am considering the ModelChange.AddedLink after the transaction is committed. For the same reason I am getting the edits from UndoManager.

What I want to accomplish is once the link is added on diagram the model will trigger the modelChanged event and I find the case when its ModelChange.AddedLink and pass the link information to my further methods. I can get all other info from link but routes info.

I understand that goXam will create some temporary points during the link is being drawn to another port but in diagram modified I wait until the transaction is complete. The following is my content of ModelChanged()

if (e.Change.Equals(ModelChange.CommittedTransaction) && e?.OldValue != null)
var edits = (e?.OldValue as UndoManager.CompoundEdit).Edits.Select(edit => edit as ModelChangedEventArgs).ToList();
case ModelChange.AddedLink:
//Trying to access link routes here

Oh, so you are looking at Link.Route.Points when the transaction has been committed. That’s good. But when I try it, I don’t have a problem with looking at the points of the route:

      model.Changed += (s, e) => {
        if (e.Change == ModelChange.CommittedTransaction) {
          var edits = e.OldValue as UndoManager.CompoundEdit;
          if (edits != null) {
            var link = myDiagram.Links.First();
            System.Diagnostics.Debug.WriteLine(edits.Name + " " + link.Route.PointsCount + " " + link.Route.Points[0].ToString());

But I get this

I tried this too but the result is the same
var route = Link.GetRoute(link.VisualElement);

but in debug mode if I browse through the link properties it will get updated. Not sure why is this happening.

Just use link.Route.

I had used link.Route earlier which gave the same results as Link.GetRoute(). This is a weird behavior where the route values are shown as NaN when the breakpoint is hit and when I explore through the properties and find Route.Points it shows the actual 6 points and link.Route is then populated and propagates through further methods.

If I don’t explore through the properties it will be sent as NaN to further methods. Is it because of Lazy evaluation for Route points or yield is used somewhere in GoXam source code?

Well, there certainly is asynchrony in any WPF application.

Perhaps you could call Route.UpdatePoints (which is a no-op if the route is valid) or Route.RecomputePoints (which forces a re-routing).

RecomputePoints() worked !! Thanks a lot !!