This is a migrated thread and some comments may be shown as answers.

Diagram save/load problem

2 Answers 167 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
nicolasf
Top achievements
Rank 2
nicolasf asked on 25 Jan 2018, 10:00 AM

Hi,

I create a program to modelize data. I use Save() function with serialize item (like TableShape Demo)

this my serialize function for my TableGraphSource :

public override void SerializeNode(NodeViewModelBase node, SerializationInfo info)
{
    base.SerializeNode(node, info);
 
    if (node is INodeSerializable)
    {
        info = (node as INodeSerializable).Serialize(info);
    }
}

each model have a Serialize method with his own parameters to serialize

It's the same for Deserialize TableGraphSource :

public override NodeViewModelBase DeserializeNode(IShape shape, SerializationInfo info)
       {
           NodeViewModelBase node = null;
           if (shape is TableShapeMulti)
           {
               var table = new TableModelMulti();
               node = table.Deserialize(info);
           }
           else if (shape is TableShape)
           {
               var table = new TableModel();
               node = table.Deserialize(info);
           }
           else if (shape is ShapeShape)
           {
               if (null != info["Content"])
               {
                   switch (info["Content"].ToString())
                   {
                       case "Controls.Entity.Models.ShapeModel":
                           var _sm = new ShapeModel();
                           node = _sm.Deserialize(info);
                           break;
                      ...
                       default:
                           var shapeModel = Activator.CreateInstance(Type.GetType(info["Content"].ToString()));
                           if (shapeModel is ShapeModel)
                               node = (shapeModel as ShapeModel).Deserialize(info);
                           break;
                   }
               }
 
           }
           else
           {
               var row = new RowModel();
               row.Deserialize(info);
               node = row;
           }
           if (null != node)
           {
               if (info["Position"] != null)
                   node.Position = Utils.ToPoint(info["Position"].ToString()).Value;
 
               if (info[this.NodeUniqueIdKey] != null)
               {
                   var nodeUniquekey = info[this.NodeUniqueIdKey].ToString();
                   if (!this.CachedNodes.ContainsKey(nodeUniquekey))
                   {
                       this.CachedNodes.Add(nodeUniquekey, node);
                   }
               }
           }
 
           return node;
       }

 

Saving is OK and Reloading is OK (all data are correctly affected) but i have a problem with ContainerShape : Width, Height, Position (X,Y) properties are not binding  anymore between shape and model when i reload diagram.

I use styleSelector to link shape with model (my app is based on TableShape demo for code structure)

Can you help me please ? Thanks

2 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 29 Jan 2018, 02:50 PM
Hi Nicolas,

By default, RadDiagramItem provides a limited set of properties that are serialized. So, you need to extend the default serialization of the control. This topic is discussed in greater detail in the Serialization article and its Extending RadDiagram Serialization section in particular.

Can you please take a look at it?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
nicolasf
Top achievements
Rank 2
answered on 31 Jan 2018, 08:55 AM
Thanks for your help,

in fact , i've just forgot to set Position and Size to null when i serialize my model.
Have a nice day,

Nicolas
Tags
Diagram
Asked by
nicolasf
Top achievements
Rank 2
Answers by
Stefan
Telerik team
nicolasf
Top achievements
Rank 2
Share this question
or