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.