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

Serialize and DeSerialize CustomControl and Diagram

1 Answer 239 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Abhinav
Top achievements
Rank 1
Abhinav asked on 11 Jul 2014, 07:55 AM
Hello there,

I`ll first explain my requirement.

I have a CustomControl deriving from  RadDiagramShapeBase that act as a symbol .Now i am adding customcontrol to a radDiagram.

On double clicking the customcontrol a new window popups that contains various textboxes that defines the symbol for eg: if symbol is a person,then the mainwindow consist of attributes eg name,ssn,address etc.

the mainwindow follows mvvm its has its respective viewmodel and model.

Now my problem:

I am  serializing the application state as two files,First the diagram (view level): I am serializing the radDiagram that consist of customcontrol (symbol) as a string. ( model level): I am serializing mainview`s model as binary serialization  as a seperate file.

Now this becomes a very difficult for me manage two file because i have to zip it into single file then unzip it and this process is not safe.
(Also i have to depend on 3rd party unzip tools!!!!)
 
My Requirement

SO is there any way so that i can serialize my attribute in the customcontrol (symbol) itself along with the radDiagram as  a single file i.e along with the diagram.

Or 

Can You provide me  any idea to achieve my result!!!!!


Thanks and Regards,
Abhinav



1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 15 Jul 2014, 11:07 AM
Hi,

I am happy to inform you that there is a straightforward approach that you can use in this particular scenario. But first let me try to explain how a regular MVVM implementation should be constructed when using the RadDiagram framework. 

You should have exposed a MainViewModel. That class should be set as DataContext of the RadDiagram. Also, it should expose a custom graph source and the RadDiagram.GraphSource should be bound to it.
Furthermore, your custom graph source should derive from the SerializableGraphSourceBase class. This will allow you to override the SerializeNode(), DeserializeNode(), SerializeLink() and DeserializeLink() methods. In these methods you will be able to manually serialize/deserialize the custom properties exposed by your custom shapes and connections. By default the RadDiagram saves all base properties (e.g. Height, Width, Content... you can find full list here) of the shapes and connections but you should take care of the custom ones.

Now when the structure is clear, let me try to elaborate on the serialization process. When you need to serialize the current state of the RadDiagram you can call its Serialize() method. This method returns an object of type SerializationInfo. This object can be used to store data held by your MainViewModel and/or by your custom graph source. You need to keep in mind that the Serialize() method of the RadDiagram will call the SerializeNode() and SerializeLink() methods of the graph source. Hence, the returned object will hold all the properties that are serialized by default along with the custom properties that you have manually serialized in your custom graph source. After receiving that object you will be able to manually add additional properties. For example properties, exposed by your MainViewModel and/or your custom graph source.

Once the serialization process is finished, you will be able to call the RadDiagram.Deserialize() method and the RadDiagram will automatically recreate the graph source by calling the DeserializeNode() and DeserializeLink() methods defined in your custom graph source. 
Furthermore, you will be able to manually deserialize the properties that were earlier serialized.

For your convenience I modified our XAML SDK MVVM project so that now it exposes MainViewModel and demonstrates the explained approach. Please take a look at it and let us know if you need any further assistance.

Regards,
Pavel R. Pavlov
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Diagram
Asked by
Abhinav
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or