I'm working on an IDE-like application that uses the Docking and MDI product. I want my app to mirror Visual Studio's behavior of restoring previously opened document windows when loading a project. After reading through the chm file's Layout Serialization section, I'm still looking for help with implementation specifics.
Let's assume my application is using the dock site's DocumentItemsSource list to create document windows whose DataContexts are bound to view models. These view models come from a TreeView that looks similar to the Visual Studio solution explorer. Specifically, the view models represent files on disk.
It seems like the right approach is to:
- Serialize with the layout serializer's SerializationBehavior set to All
- Deserialize with the layout serializer's DocumentWindowDeserializationBehavior and ToolWindowDeserializationBehavior values set to AutoCreate
- Use the DockingWindowSerializing event handler to provide my document windows with a DataContext as they're deserialized
However, there's a problem during deserialization since I won't know which view models to assign to which document windows. A possible solution is to use the ObjectSerialized event to associate a file path with each document window, and then retrieve that path in the DockingWindowDeserializing event. That path would allow me to obtain the associated view model and assign it to the document window's DataContext.
Is the above the recommended approach for serialization with MVVM?