Skip to main content

Save and Restore the Layout of Dock Panels and Controls

  • 4 minutes to read

DockLayoutManager allows you to save (serialize) its layout to an XML file/Stream and then restore (deserialize) it.

Run Demo: Dock Layout Manager - Serialzation Demo

Run Demo: Dock Layout Manager - MVVM Serialzation Demo

Requirements

To save/restore the layout of the DockLayoutManager‘s child items, specify the unique x:Name/BindableName property values for all the dock UI and layout UI items.

If you save/restore the DockLayoutManager‘s layout in the MVVM application, you should bind each dock/layout item’s BaseLayoutItem.BindableName property to a view model’s property that stores a unique item’s identifier.

If you link two or more dock layout managers, items must have unique names across these managers. Refer to the following topic for more information on how to link multiple dock layout managers: Move Panels Between DockLayoutManager Instances.

Available Methods

The following table lists methods that you can use to save/restore layouts of dock panels, layout items, and child controls:

Save Methods Restore Methods
DockLayoutManager.SaveLayoutToStream DockLayoutManager.RestoreLayoutFromStream
DockLayoutManager.SaveLayoutToXml DockLayoutManager.RestoreLayoutFromXml

The history of dock operations is not saved when layouts are saved to a data store.

The following code sample saves and restores the layout of the DockLayoutManager‘s child items:

System.IO.Stream str;
// Create and save the layout of dock panels to a new memory stream
str = new System.IO.MemoryStream();
DockLayoutManager1.SaveLayoutToStream(str);
str.Seek(0, System.IO.SeekOrigin.Begin);
//...
// Load the layout of dock panels from the memory stream
str.Seek(0, System.IO.SeekOrigin.Begin);
DockLayoutManager1.RestoreLayoutFromStream(str);

Refer to the following topic for more information on how to save/restore the layout of DevExpress WPF Controls: Save/Restore Control Layout.

Limitation

The DockLayoutManager‘s RestoreLayoutFrom* methods do not restore its panel’s position if it is snapped to a side of a screen.

Serialize Layouts of Unopened LayoutGroups

The DevExpress WPF Controls serizalization saves/restores layouts of controls that exist in the application’s visual tree. Because of that, it does not save/restore contents of the unopened LayoutGroup tabs.

To save/restore layouts of serializable DevExpress WPF Controls that are placed into a LayoutGroup tab, set the tab’s LayoutGroup.TabContentCacheMode property to TabContentCacheMode.CacheAllTabs. In this case, the tab loads its contents to a visual tree when the control is loaded.

View Example: Serialize DockLayoutManager When TabbedDocumentUIService Is Used

Restore Items that do not Exist in the DockLayoutManager

Set a DockLayoutManager‘s RestoreLayoutOptions.RemoveOldPanels attached property to false to restore the DockLayoutManager‘s panels that exist in a saved layout but do not exist in the DockLayoutManager:

<dxdo:DockLayoutManager x:Name="dockManager" dxdo:RestoreLayoutOptions.RemoveOldPanels="False">

WPF Docking - Restore Serialized Panels

You can also use the following properties to restore other layout elements that exist in a saved layout but do not exist in the DockLayoutManager:

Property Description
AddNewLayoutControlItems

Gets or sets whether the Dock Layout Manager should automatically add layout control items that are absent in the current layout, but present in its restored version. This is a dependency property.

AddNewLayoutGroups

Gets or sets whether the Dock Layout Manager should automatically add layout groups that are absent in the current layout, but present in its restored version. This is a dependency property.

AddNewPanels

Gets or sets whether the Dock Layout Manager should automatically add layout panels that are present in the current layout, but absent in its restored version, to its ClosedPanels collection. This is a dependency property.

RemoveOldLayoutControlItems

Gets or sets whether the Dock Layout Manager should automatically remove all layout groups that are absent in the restored layout version. This is a dependency property.

RemoveOldLayoutGroups

Gets or sets whether the Dock Layout Manager should automatically remove all layout control items that are absent in the restored layout version. This is a dependency property.

Restore Closed Panels on Layout Restore

When you restore a DockLayoutManager‘s layout, panels that exist in the DockLayoutManager but do not exist in the saved layout are moved to the ClosedPanels collection. You can use the DockLayoutManager‘s APIs to restore these panels manually.

WPF Docking - Restore Serialized Panels

Refer to the following topic for more information on how to manipulate panels in code: Manage Dock Panels in Code.

Remove Closed Panels

To remove panels that exist in the DockLayoutManager but do not exist in the saved layout, set the DockLayoutManager‘s RestoreLayoutOptions.AddNewPanels attached property to false:

<dxdo:DockLayoutManager x:Name="dockManager" dxdo:RestoreLayoutOptions.AddNewPanels="False">
See Also