Serialize and DeSerialize CustomControl and Diagram

2 posts, 0 answers
  1. Abhinav
    Abhinav avatar
    5 posts
    Member since:
    Apr 2014

    Posted 11 Jul 2014 Link to this post

    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.


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

    Thanks and Regards,

  2. Pavel R. Pavlov
    Pavel R. Pavlov avatar
    1237 posts

    Posted 15 Jul 2014 Link to this post


    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.

    Pavel R. Pavlov
    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.
Back to Top