Loading Diagram is not preserved

When using Diagram.LoadDiagram(data), with a NodeCollection (ObservableCollection<DiagramNode> NodeCollection), it seems that Diagram.Nodes and the items in NodeCollection become desynchronised.So, after using LoadDiagram, on the next render Diagram.Nodes will have the nodes in data, but NodeCollection will remain on its previous state. So, after a StateHasChanged() is called or the diagram is re-rendered, Diagram.Nodes() will be assigned the contents from NodeCollection but lose the nodes it loaded from data.

The attatched file, which includes only small modifications on the serialization demo illustrates the issue, as after loading the nodes in the string, they can only be clicked once, and subsequent clicks throw null exceptions.

Attachment: Serialization_33a12bd7.zip

3 Replies

AR Aravind Ravi Syncfusion Team May 20, 2020 10:51 AM UTC

Hi Sergio, 

We have modified a sample for how to use selection change event. Could you please confirm us, while try to deselect the selected node null reference exception occurs. If yes, when you select the node in diagram, selectionchange event gets fired. At first time when you select the node, selection node comes in newValue arguments. If you deselect the selected node, nodes in newValue set as o and deselected node comes in old value arguments. Please find the below code snippet for how to selection change event when select or deselect the node. 

public void SelectionChange(IBlazorSelectionChangeEventArgs arg) 
   
        if (arg.State == EventState.Changed) 
       
            if (arg.Type == ChangeType.Addition) 
           
                var node = Diagram.GetNode(arg.NewValue.Nodes[0].Id); 
                Debug.WriteLine(node.Id); 
            } else 
           
                var node = Diagram.GetNode(arg.OldValue.Nodes[0].Id); 
                Debug.WriteLine(node.Id); 
           
       
   

In case if we misunderstood your requirement, please share us a video demonstration of issue or share the requirement in detail which would help us to proceed further. 

Regards 
Aravind Ravi 



PA Paul January 15, 2021 04:32 AM UTC

Hi Sergio,

Did you ever fix this problem?

We are experiencing something similar, where we have a child Blazor component on a page containing a diagram control and when the parent component is changed and we update the NodeCollection as a result of the change in cascading parameters from the parent to the child (and then call StateHasChanged()), it seems that nothing happens because the original nodes are displayed instead of the new ones.
https://www.syncfusion.com/forums/161274/child-component-is-not-rendering

Thanks.
Paul


GG Gowtham Gunashekar Syncfusion Team January 18, 2021 12:43 PM UTC

Hi Sergio, 
Please follow the below steps if you want to create a new diagram in the existing diagram: 
1) Clear the diagram by calling “Diagram.Clear(); “API, it will remove the existing node and connector and then clear the node and connector collection.  
2) Then add the required nodes and connector in the respected collection as mentioned below. 
  public void Refresh(string Id)  
    {  
        Diagram.Clear();  
        NodeCollection.Add(NewNode("old Diagram","green")  
        ConnectorCollection.Add(NewConnecctor ("old Diagram","red")  
     }  
  
Regards,  
Gowtham  
 


Loader.
Up arrow icon