Reputation: 3558
I am creating small graphics editor which have DocumentViewModel class (inherits from my PaneViewModel class which inherits from GalaSoft.MVVMLIGHT.ViewModelBase). DocumentViewModel represents one image (application can handle few images at one time so i decided to have collection of DocumentViewModel). I'd like to serialize DocumentViewModel when saving a project and deserialize when loading a project. However I can't do this because application throws an exception while serializing ( "GalaSoft.MvvmLight.ViewModelBase isn't marked as serializable ). Is there any workaround for this problem? Is it correct to use serialization as loading/saving mechanism?
Upvotes: 1
Views: 1332
Reputation: 7005
It sounds like you want to serialize application state. If you want to do this using MVVM Light then create an Application State service/object that gets injected into the viewmodel. Use this to manage your application state (which viewmodel is active, etc).
Have your application state service save itself when it detects that the application is saving. Have it check for a serialized object when it starts up and use this to reload the application states current settings. Viewmodels consume this to ensure that state is consistent.
Upvotes: 2