[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
 [Expand]What's Installed
 [Expand]Common Concepts
 [Collapse]MVVM Framework
    Getting Started
    Module Manager
    Saving and Restoring Application State
   Data Annotation Attributes
   Weak Event
 [Expand]Controls and Libraries
 [Expand]Scaffolding Wizard
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Saving and Restoring Application State

There are several types of state an application is often expected to restore upon restart.

  • The state of visual controls such as the selected grouping and column order of a GridControl, or the position of panels in a DockLayoutManager.
  • Dynamically injected modules. These can be automatically injected on startup. The open tabs in a browser is an example.
  • The state of particular View Models.

The Module Injection Framework refers to the first type of state as the visual state. The second and third types are grouped into the logical state.

Expanded Configuring Visual State

VisualStateService is responsible for saving visual state. Any control in the visual tree of a particular view can become a serialization root, meaning that its state and the state of all its children down the visual tree can be saved. Add the VisualStateService behavior to a control to mark it as a serialization root.

Expanded Configuring Logical State

The ISupportState<T> interface allows a ViewModel to provide a state to the MIF, that is applied when the view model is injected as part of a module.

The T-type must provide a default constructor, and if a user type also has the SerializableAttribute applied.

Expanded Saving and Restoring

The application state does not save and restores automatically even after the VisualStateService behavior is attached to suitable controls in XAML, and suitable view models have implemented the ISupportState<T> interface.

The IModuleManagerBase.Save method allows querying the current application state.

Both the logical and visual state of a particular region are returned. The application developer is responsible for saving the queried state to persistent storage, for example, application settings.

When an application starts, it may decide whether to restore the saved state or disregard it. The IModuleManagerBase.Restore method restores the application state.

The method returns false if for some reason the state has been corrupted.

Is this topic helpful?​​​​​​​