Saving and Restoring the Layout of Dock Panels and Controls

  • 2 minutes to read

The layout of dock panels and the layout of controls within panels/groups can be saved to a data store (an XML file or stream), and then restored from this data store, overriding the changes made since the layout was saved. This document provides more information on this topic.

Saving and Restoring the Layout of Dock Panels and Controls

The layout of dock panels, layout items and controls can be saved to a data store manually using one of the following methods: DockLayoutManager.SaveLayoutToStream and DockLayoutManager.SaveLayoutToXml. To restore a layout, use one of the corresponding methods: DockLayoutManager.RestoreLayoutFromStream or DockLayoutManager.RestoreLayoutFromXml.

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

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);

To correctly save and restore the layout of controls, ensure that all dock items and layout items have the Name properties specified or the BaseLayoutItem.BindableName property bound. If two or more managers are linked, item names must be unique across these managers.

Layout Settings

By default, dock panels that are present within a saved layout, but not present in the DockLayoutManager, are not created when calling the RestoreLayoutFrom... methods. To recreate these panels, set the RestoreLayoutOptions.RemoveOldPanels attached property for a DockLayoutManager to False

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

Panels that are present in the DockLayoutManager, but absent in the saved layout, are moved to the to the ClosedPanels collection during the restore layout operation. You can traverse through these panels and restore them manually (see: Managing Dock Panels in Code). To force the DockLayoutManager to completely remove such panels, disable the attached RestoreLayoutOptions.AddNewPanels property in your DockLayoutManager:

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