Link routes resetting

Hi,

we have a problem with links routing after reloading nodes and links in the diagram.
We do not reload the whole Diagram - we just clear nodes and links in Diagrams model, and than - we add nodes and links, previously saved. Reloading takes place in a transaction. After transaction commit, link routes are resetting. I know, that there were already posted some issues to this problem. But I couldn’t get this to work.

Here is the code that reloads all nodes and links:

                _model.Model.StartTransaction("initial");
                if (_model.Nodes.Any() && _model.Links.Any())
                {
                    _model.Nodes.Clear();
                    _model.Links.Clear();
                }

                foreach (var node in nodes)
                {
                    var model = new NodeViewModel(node);
                    _model.Nodes.Add(model);
                }

                foreach (var link in links)
                {
                    var model = new LinkViewModel(link);
                    _model.Links.Add(model);
                }
                _model.Model.CommitTransaction("initial");

In LinkViewModel constructor, which inherits: GraphLinksModelLinkData<string, string>, I write it’s Points value.

A have also tried to write Link.Route values in PartManagers’ overrided OnModelChange from my LinkViewModel - but it still did not work.

Do you avoid the problem if you create a new model and replace Diagram.Model? Instead of modifying the existing model.

No. I tried this method, but It also does not help.

Are you doing what some of the samples do in order to load link routes? For example, the Draggable Link sample does this when loading a model:

      myDiagram.PartManager.UpdatesRouteDataPoints = false;  // tell the CustomPartManager that we're loading

        XElement root = XElement.Parse(/*Demo.MainPage.Instance.*/SavedXML);
        // set the Route.Points after nodes have been built and the layout has finished
        myDiagram.LayoutCompleted += LoadLinkRoutes;
        model.Load<MyData, MyLinkData>(root, "Node", "Link");

and:

    // no data-binding of Route.Points means we have to copy the Points data explicitly
    private void LoadLinkRoutes(Object s, EventArgs e) {
      // just set the Route points once per Load
      myDiagram.LayoutCompleted -= LoadLinkRoutes;
      foreach (Link link in myDiagram.Links) {
        var d = link.Data as MyLinkData;
        if (d == null || d.Points == null) continue;
        link.Route.Points = (IList<Point>)d.Points;
      }
      myDiagram.PartManager.UpdatesRouteDataPoints = true;  // OK for CustomPartManager to update Transition.Points automatically
    }

Ok, this time it is working. Thanks for help.