# Save and Restore the Layout of Dock Panels and Controls | WPF Controls | DevExpress Documentation

[DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager) allows you to save (serialize) its **layout** to an [XML file](https://docs.microsoft.com/en-us/dotnet/standard/serialization/xml-and-soap-serialization)/[Stream](https://learn.microsoft.com/dotnet/api/system.io.stream) and then restore (deserialize) it.

[Run Demo: Dock Layout Manager - Serialzation Demo](dxdemo://Wpf/DXDocking/MainDemo/Serialization)

[Run Demo: Dock Layout Manager - MVVM Serialzation Demo](dxdemo://Wpf/DXDocking/MainDemo/MVVMSerialization)

[DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager) uses [DXSerializer](/WPF/DevExpress.Xpf.Core.Serialization.DXSerializer) to save and restore its layout. You can use [DXSerializer](/WPF/DevExpress.Xpf.Core.Serialization.DXSerializer)‘s properties and events to adjust how the serialization works. Refer to the following help topics for more information:

- [Save/Restore Control Layout](/WPF/7391/common-concepts/save-and-restore-layouts)
- [DXSerializer Events - Advanced Scenarios](/WPF/7410/common-concepts/saving-and-restoring-layouts/advanced-scenarios)

If you want to prevent certain properties from being saved/restored, use the [AllowProperty](/WPF/DevExpress.Xpf.Core.Serialization.DXSerializer.AllowProperty) attached event at the [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager) level. Refer to the following help topic for more information: [Do not Restore a Control’s Predefined Property](/WPF/7410/common-concepts/saving-and-restoring-layouts/advanced-scenarios#do-not-restore-a-controls-predefined-property). 

The other [DXSerializer](/WPF/DevExpress.Xpf.Core.Serialization.DXSerializer) attached events are raised for each separate [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager) element (group, panel, item, etc.)

## Requirements

To save/restore the layout of the [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager)‘s child items, specify the unique `x:Name`/[BindableName](/WPF/DevExpress.Xpf.Docking.BaseLayoutItem.BindableName) property values for all the [dock UI](/WPF/7209/controls-and-libraries/layout-management/dock-windows/dock-items) and [layout UI](/WPF/7223/controls-and-libraries/layout-management/dock-windows/layout-items) items. 

If you save/restore the [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager)‘s layout in the MVVM application, you should bind each dock/layout item’s  [BaseLayoutItem.BindableName](/WPF/DevExpress.Xpf.Docking.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](/WPF/400980/controls-and-libraries/layout-management/dock-windows/move-layout-panels-between-dock-layout-managers).

## 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](/WPF/DevExpress.Xpf.Docking.DockLayoutManager.SaveLayoutToStream%28System.IO.Stream%29) | [DockLayoutManager.RestoreLayoutFromStream](/WPF/DevExpress.Xpf.Docking.DockLayoutManager.RestoreLayoutFromStream%28System.IO.Stream%29) |
| [DockLayoutManager.SaveLayoutToXml](/WPF/DevExpress.Xpf.Docking.DockLayoutManager.SaveLayoutToXml%28System.String%29) | [DockLayoutManager.RestoreLayoutFromXml](/WPF/DevExpress.Xpf.Docking.DockLayoutManager.RestoreLayoutFromXml%28System.String%29) |

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](/WPF/DevExpress.Xpf.Docking.DockLayoutManager)‘s child items:

- C#
- VB.NET

<section id="tabpanel_poefS1xb53_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code data-code-links="{&quot;RemoveOldPanels&quot;:&quot;/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.RemoveOldPanels&quot;,&quot;AddNewPanels&quot;:&quot;/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.AddNewPanels&quot;}" class="lang-csharp">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);
</code></pre></section>
<section id="tabpanel_poefS1xb53_tabid-vb" role="tabpanel" data-tab="tabid-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;RemoveOldPanels&quot;:&quot;/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.RemoveOldPanels&quot;,&quot;AddNewPanels&quot;:&quot;/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.AddNewPanels&quot;}" class="lang-vb">Dim str As System.IO.Stream
&#39; 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)
&#39; ..
&#39; Load the layout of dock panels from the memory stream
str.Seek(0, System.IO.SeekOrigin.Begin)
DockLayoutManager1.RestoreLayoutFromStream(str)
</code></pre></section>

Refer to the following topic for more information on how to save/restore the layout of DevExpress WPF Controls: [Save/Restore Control Layout](/WPF/7391/common-concepts/save-and-restore-layouts).

### Limitation

The [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.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](/WPF/DevExpress.Xpf.Docking.LayoutGroup) tabs.

To save/restore layouts of serializable DevExpress WPF Controls that are placed into a [LayoutGroup](/WPF/DevExpress.Xpf.Docking.LayoutGroup) tab, set the tab’s [LayoutGroup.TabContentCacheMode](/WPF/DevExpress.Xpf.Docking.LayoutGroup.TabContentCacheMode) property to [TabContentCacheMode.CacheAllTabs](/WPF/DevExpress.Xpf.Core.TabContentCacheMode). 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](https://github.com/DevExpress-Examples/wpf-docklayoutmanager-serialize-docklayoutmanager-when-tabbeddocumentuiservice-is-used)

## Restore Items that do not Exist in the DockLayoutManager

Set a [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager)‘s [RestoreLayoutOptions.RemoveOldPanels](/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.RemoveOldPanels) attached property to `false` to restore the [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager)‘s panels that exist in a saved layout but do not exist in the [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager):

- XAML

<section id="tabpanel_poefS1xb53-1_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code data-code-links="{&quot;RemoveOldPanels&quot;:&quot;/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.RemoveOldPanels&quot;,&quot;AddNewPanels&quot;:&quot;/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.AddNewPanels&quot;}" class="lang-xaml">&lt;dxdo:DockLayoutManager x:Name=&quot;dockManager&quot; dxdo:RestoreLayoutOptions.RemoveOldPanels=&quot;False&quot;&gt;
</code></pre></section>

![WPF Docking - Restore Serialized Panels](/WPF/images/docking-serialization-restore-panels-from-storage.png)

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](/WPF/DevExpress.Xpf.Docking.DockLayoutManager):

| Property | Description |
| --- | --- |
| [AddNewLayoutControlItems](/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.AddNewLayoutControlItems) | Gets or sets whether the [Dock Layout Manager](/WPF/6820/controls-and-libraries/layout-management/dock-windows/getting-started/dock-layout-manager) should automatically add [layout control items](/WPF/7223/controls-and-libraries/layout-management/dock-windows/layout-items) that are absent in the current layout, but present in its restored version.<br>This is a dependency property. |
| [AddNewLayoutGroups](/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.AddNewLayoutGroups) | Gets or sets whether the [Dock Layout Manager](/WPF/6820/controls-and-libraries/layout-management/dock-windows/getting-started/dock-layout-manager) should automatically add layout groups that are absent in the current layout, but present in its restored version.<br>This is a dependency property. |
| [AddNewPanels](/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.AddNewPanels) | Gets or sets whether the [Dock Layout Manager](/WPF/6820/controls-and-libraries/layout-management/dock-windows/getting-started/dock-layout-manager) should automatically add layout panels that are present in the current layout, but absent in its restored version, to its  [ClosedPanels](/WPF/DevExpress.Xpf.Docking.DockLayoutManager.ClosedPanels) collection.<br>This is a dependency property. |
| [RemoveOldLayoutControlItems](/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.RemoveOldLayoutControlItems) | Gets or sets whether the [Dock Layout Manager](/WPF/6820/controls-and-libraries/layout-management/dock-windows/getting-started/dock-layout-manager) should automatically remove all layout groups that are absent in the restored layout version.<br>This is a dependency property. |
| [RemoveOldLayoutGroups](/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.RemoveOldLayoutGroups) | Gets or sets whether the [Dock Layout Manager](/WPF/6820/controls-and-libraries/layout-management/dock-windows/getting-started/dock-layout-manager) should automatically remove all  [layout control items](/WPF/7223/controls-and-libraries/layout-management/dock-windows/layout-items) that are absent in the restored layout version.<br>This is a dependency property. |

## Restore Closed Panels on Layout Restore

When you restore a [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager)‘s layout, panels that exist in the [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager) but do not exist in the saved layout are moved to the [ClosedPanels](/WPF/DevExpress.Xpf.Docking.DockLayoutManager.ClosedPanels) collection. You can use the [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager)‘s APIs to restore these panels manually. 

![WPF Docking - Restore Serialized Panels](/WPF/images/docking-serialization-remove-unsaved-panels.png)

Refer to the following topic for more information on how to manipulate panels in code: [Manage Dock Panels in Code](/WPF/15540/controls-and-libraries/layout-management/dock-windows/managing-dock-panels-in-code). 

### Remove Closed Panels

To remove panels that exist in the [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager) but do not exist in the saved layout, set the [DockLayoutManager](/WPF/DevExpress.Xpf.Docking.DockLayoutManager)‘s [RestoreLayoutOptions.AddNewPanels](/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.AddNewPanels) attached property to `false`: 

- XAML

<section id="tabpanel_poefS1xb53-2_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code data-code-links="{&quot;RemoveOldPanels&quot;:&quot;/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.RemoveOldPanels&quot;,&quot;AddNewPanels&quot;:&quot;/WPF/DevExpress.Xpf.Docking.RestoreLayoutOptions.AddNewPanels&quot;}" class="lang-xaml">&lt;dxdo:DockLayoutManager x:Name=&quot;dockManager&quot; dxdo:RestoreLayoutOptions.AddNewPanels=&quot;False&quot;&gt;
</code></pre></section>

See Also

[Save/Restore Control Layout](/WPF/7391/common-concepts/save-and-restore-layouts)