# Save and Restore Item Layout | WPF Controls | DevExpress Documentation

Controls included in the **Xpf.LayoutControl** library provide methods to dynamically save and restore their item layouts to and from streams or local storage.

## Layout and Data Layout Control

Control layouts within a [Layout Control](/WPF/8147/controls-and-libraries/layout-management/tile-and-layout/layout-and-data-layout-controls/layout-control) can be saved to a data store and restored at a later time. This allows your end users to customize a layout in [Customization Mode](/WPF/8154/controls-and-libraries/layout-management/tile-and-layout/layout-and-data-layout-controls/customization-mode) and save the layout to a data store.

To save a layout to a data store, use LayoutControl’s [LayoutControlBase.WriteToXML](/WPF/DevExpress.Xpf.LayoutControl.LayoutControlBase.WriteToXML%28System.Xml.XmlWriter%29) inherited method. The [LayoutControl.ReadFromXML](/WPF/DevExpress.Xpf.LayoutControl.LayoutControl.ReadFromXML%28System.Xml.XmlReader%29) method restores a saved layout.

Note

To correctly save and then restore the layout of items, you need to assign names to the items. If names are not specified, the layout will be correctly restored, provided that the LayoutControl’s/LayoutGroup’s item collection (the order and number of items) wasn’t modified after the layout was saved.

To load a layout, we recommend using the **Loaded** event of a UserControl or a window.

When saving/loading layouts to a data store, only properties that can be changed by an end user during layout customization are stored/restored.

If you need to save/load custom properties when a layout is saved/loaded, handle the [LayoutControl.WriteElementToXML](/WPF/DevExpress.Xpf.LayoutControl.LayoutControl.WriteElementToXML) and [LayoutControl.ReadElementFromXML](/WPF/DevExpress.Xpf.LayoutControl.LayoutControl.ReadElementFromXML) events.

The following example shows how to save the layout of items of a [LayoutControl](/WPF/DevExpress.Xpf.LayoutControl.LayoutControl) object to a stream, and then restore the layout. The [LayoutControlBase.WriteToXML](/WPF/DevExpress.Xpf.LayoutControl.LayoutControlBase.WriteToXML%28System.Xml.XmlWriter%29) and [LayoutControl.ReadFromXML](/WPF/DevExpress.Xpf.LayoutControl.LayoutControl.ReadFromXML%28System.Xml.XmlReader%29) methods are used to do this.

- C#

<section id="tabpanel_ozy-UjBP4d_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code data-code-links="{&quot;/ (System.Xml)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.xml&quot;,&quot;/ (System.IO)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.io&quot;}" class="lang-csharp">using System.Xml;
using System.IO;

MemoryStream stream = new MemoryStream();

//Save the layout
XmlWriter writer = XmlWriter.Create(stream);
myLayoutControl.WriteToXML(writer);
writer.Close();

//Load the layout
stream.Seek(0, SeekOrigin.Begin);
XmlReader reader = XmlReader.Create(stream);
myLayoutControl.ReadFromXML(reader);
reader.Close();
</code></pre></section>

Note

Controls added dynamically to a Layout Control should be registered with the **RegisterName** method to save/restore their layout correctly.

The LayoutControl automatically adds items restored from an XML file to the [LayoutControl.AvailableItems](/WPF/DevExpress.Xpf.LayoutControl.LayoutControl.AvailableItems) collection. You can set the [AddRestoredItemsToAvailableItems](/WPF/DevExpress.Xpf.LayoutControl.LayoutControl.AddRestoredItemsToAvailableItems) property to `false` to prevent moving restored items to the `AvailableItems` collection.

## Other Controls

Other controls provided by the **Xpf.LayoutControl** library also derive from the [LayoutControlBase](/WPF/DevExpress.Xpf.LayoutControl.LayoutControlBase) class and thus, can dynamically save and restore their layouts by calling the [LayoutControlBase.WriteToXML](/WPF/DevExpress.Xpf.LayoutControl.LayoutControlBase.WriteToXML%28System.Xml.XmlWriter%29) and [LayoutControlBase.ReadFromXML](/WPF/DevExpress.Xpf.LayoutControl.LayoutControlBase.ReadFromXML%28System.Xml.XmlReader%29) methods.

The number of settings that can be saved is limited. Typically, you can only save and restore item sizes and their orders. Global control properties (for example, the [Flow Layout Control](/WPF/8148/controls-and-libraries/layout-management/tile-and-layout/flow-layout-control)‘s orientation or its splitters’ visibility) is not saved.

See Also

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