How to serialize the custom object in NodeViewModel?
Hi,
I try to add custom object to NodeViewModel and serialize this custom object with the node by node serialize function.
And I follow this instruction: https://help.syncfusion.com/wpf/sfdiagram/serialization
But I still can't find my custom object in serialize XML file.
My custom object:
public class POS_Contract : INotifyPropertyChanged
{
public POS_Contract()
{
Nodettla = "ggla";
}
[DataMember]
public string Nodettla
{
get;
set;
}
public event PropertyChangedEventHandler PropertyChanged;
}
=======================
and my node add function:
public void addPosNode(double OffsetX, double OffsetY)
{
sf_diagram.KnownTypes = () => new List<Type>()
{
typeof(POS_Contract)
};
POS_Contract pc = new POS_Contract();
NodeViewModel node = new NodeViewModel()
{
Content = pc,
ID = "node_pos_" + Guid.NewGuid(),
Constraints = NodeConstraints.Default & ~NodeConstraints.Resizable & ~NodeConstraints.Rotatable,
OffsetX = OffsetX,
OffsetY = OffsetY,
Pivot = new Point(0, 0),
UnitWidth = 120,
UnitHeight = 40,
Shape = App.Current.Resources["Process"],
//Add node shape style
ShapeStyle = stylePosNode.styleNode,
Annotations = new ObservableCollection<AnnotationEditorViewModel>()
{
new AnnotationEditorViewModel()
{
Content="POS",
}
},
Ports = new ObservableCollection<NodePortViewModel>()
{
new NodePortViewModel()
{
ID = "POS_IN",
Constraints = PortConstraints.Default & ~PortConstraints.InheritPortVisibility,
PortVisibility = PortVisibility.Visible,
NodeOffsetX = 0.5 ,
NodeOffsetY = 0,
ShapeStyle = stylePosNode.styleInPort,
Shape = new EllipseGeometry() { RadiusX= 5, RadiusY = 5 },
},
new NodePortViewModel()
{
ID = "POS_OUT",
Constraints = PortConstraints.Default & ~PortConstraints.InheritPortVisibility,
PortVisibility = PortVisibility.Visible,
NodeOffsetX = 0.5 ,
NodeOffsetY = 1,
ShapeStyle = stylePosNode.styleInPort,
Shape = new EllipseGeometry() { RadiusX= 5, RadiusY = 5 },
}
}
};
nodes.Add(node);
sf_diagram.Nodes = nodes;
}
======================
Thanks!
SIGN IN To post a reply.
3 Replies
KR
Karkuvel Rajan Shanmugavel
Syncfusion Team
April 3, 2018 10:32 AM UTC
Hi Nathaniel,
NodeViewModel’s Content will not be serialized by default. Please add a custom property by deriving NodeViewModel and allow it to serialize as shown in following code example.
Code Example:
|
public class customnode : NodeViewModel
{
[DataMember]
public object customcontent
{
get { return Content; }
set { Content = value; }
}
}
|
We have prepared a sample to demonstrate this.
Sample Link: http://www.syncfusion.com/downloads/support/forum/136788/ze/Custom_Object_Serialization-1592640181
Regards,
Karkuvel Rajan.S
NC
Nathaniel Chen
April 12, 2018 08:56 AM UTC
Thanks Rajan,
I understand and solved this problem.
Appreciate your help :)
KR
Karkuvel Rajan Shanmugavel
Syncfusion Team
April 13, 2018 06:01 AM UTC
Hi Nathaniel,
Thanks, please let us know whether you need any other assistance.
Regards,
Karkuvel Rajan.S
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
NC Nathaniel Chen
- Apr 2, 2018 09:28 AM UTC
- Apr 13, 2018 06:01 AM UTC