Node.ID not saved

  1. Create nodes programmaticaly
  2. Set ID for each node as GUID
  3. Save diagramm to file (serialize)
  4. Read diagramm from file (desirealize)
  5. ID is NULL

Cannot restore diagramm fo business object, because ID prop is null

3 Replies 1 reply marked as answer

KR Karkuvel Rajan Shanmugavel Syncfusion Team September 28, 2021 05:34 AM UTC

Hi Anton, 
 
Reported Issue: Node.ID property not getting serialized. 
 
The reported issue is not an issue it’s the actual behavior in our SfDiagram control. In our SfDiagram control, we have used ID as an object type property because IDs are provided by the customers based on their requirements. So we have not used ID as a unique type. If you want to serialize the ID then you have to create a custom property in your diagram elements and serialize them by adding the DataMember attribute to them. To know more about how to serialize custom property please follow the below documentation link. 
 
 
Regards, 
Karkuvel Rajan S  



AN Anton September 28, 2021 08:01 PM UTC

Hello!

Yes, i did it in that way.

But, ID is used in connections... so i need restore ID each time,,,,



But there is another problem, when i drop object from treeview and create object via arg


args.Source = new NodeSFEx()

{


UnitHeight = 100,

UnitWidth = 200,

Name = tar.NameTech,

Content = tar,

ID = tar.Uid,


//Constraints=NodeConstraints.Default|~NodeConstraints.

Annotations = new AnnotationEditorViewModel()

{

Content = tar.NameTech,

},

ObjectUid = tar.Uid,

ObjectType = (int)NodeSFExTypes.Indicator,

};


where

public class NodeSFEx

: NodeViewModel

{

[DataMember]

public int ObjectType { get; set; }


[DataMember]

public Guid ObjectUid { get; set; }


[DataMember]

public string AddInfo { get; set; } = "";

}

But, when object added to diagram it has custom fields (and objectUID) are getting null...

Оbjects, that created proggramaticly working as expected..



For example, in event

(_Diagramm.Info as IGraphInfo).ItemAdded

custom props already null...



KR Karkuvel Rajan Shanmugavel Syncfusion Team September 29, 2021 05:29 AM UTC

Hi Anton, 
 
Please find the response for your queries in below table.  
 
Query 
Response 
 
Yes, i did it in that way. 
But, ID is used in connections... so i need restore ID each time,,,, 
 
 
In our SfDiagram control, if we use IDs for create Connection then internally we have update the SourceNode and TargetNode based on the SourceNodeID and TargetNodeID.  
 
If you want to restore ID of the diagram element then use CustomID property to serialize and deserialize and assign its value to ID. We have prepared a simple sample for this requirement and attached the same below. 
 
  
 
when i drop object from treeview and create object via arg 
 
when object added to diagram it has custom fields (and objectUID) are getting null... 
Оbjects, that created proggramaticly working as expected.. 
 
 
 
In our SfDiagram control, we have clone the values of our default NodeViewModel properties alone. So for custom node you have to write clone functionality for the custom properties. Please find the code example below. 
 
Code Example: 
 
 
public class CustomNode : NodeViewModel , ICloneable 
{ 
        public string CustomID 
        { 
            get 
            { 
                return _mcustomID; 
            } 
            set 
            { 
                if (_mcustomID != value) 
                { 
                    _mcustomID = value; 
                    ID = _mcustomID; 
                    OnPropertyChanged("CustomID"); 
                } 
            } 
        } 
 
        public object Clone() 
        { 
            CustomNode clonedobject = new CustomNode(); 
            clonedobject.CustomID = this.CustomID; 
            return clonedobject; 
        }
} 
 
 
Please modify your custom node class based on the provided code example. 
 
 
Regards, 
Karkuvel Rajan S 


Marked as answer
Loader.
Up arrow icon