Skip to main content

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 the layout, use one of the corresponding methods: DockLayoutManager.RestoreLayoutFromStream or DockLayoutManager.RestoreLayoutFromXml.

The history of dock operations is not saved when you save a layout 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 items have the Name properties specified.

#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 ResoreLayoutFrom... methods. To recreate these panels, set the RestoreLayoutOptions.RemoveOldPanels attached property for a DockLayoutManager to False.


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