What's the recommended way to use serialization, with MVVM, to restore document windows?

Docking/MDI for WPF Forum

Posted 12 years ago by Craig - Varigence, Inc.
Version: 12.1.0562
Avatar

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:

  1. Serialize with the layout serializer's SerializationBehavior set to All
  2. Deserialize with the layout serializer's DocumentWindowDeserializationBehavior and ToolWindowDeserializationBehavior values set to AutoCreate
  3. 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?

Thanks,

-Craig

Comments (1)

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Craig,

Yes it sounds like you've got it.  The other thing you can do is serialize the Name or FileName properties and key off one of those instead so that you know which view models to use.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.