Back to Devexpress

Saving and Restoring a Bar Layout

wpf-7054-controls-and-libraries-ribbon-bars-and-menu-bars-saving-and-restoring-a-bar-layout.md

latest2.9 KB
Original Source

Saving and Restoring a Bar Layout

  • Mar 25, 2022
  • 2 minutes to read

A bar layout can be saved to a data store (an XML file or a stream), and then restored from this data store, overriding the changes made since the layout was saved. This document provides information on this topic.

Saving and Restoring a Bar Layout

The BarManager provides methods to save and restore a bar layout and bar items that belong to the BarManager:

You can save the layout of multiple DevExpress visual controls residing in a single object (e.g., window) in a centralized way, using the functionality provided by the DevExpress.Xpf.Core.Serialization.DXSerializer class. See Saving and Restoring Layout Basics, to learn more.

To save the layout of a control when a window is about to close, handle the Window.Closing event. To restore the layout when the window is being loaded, handle the Window.Loaded event.

Note

To serialize the layout of Standalone Bar Controls, place them inside a BarManager.

Example

The following code saves and restores the layout of bars and bar items that belong to a BarManager:

xaml
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
<!--...-->
<dxb:BarManager x:Name="barManager1">
<!--...-->
csharp
System.IO.Stream str;
// Create and save the bar layout to a new memory stream.
str = new System.IO.MemoryStream();
barManager1.SaveLayoutToStream(str);
str.Seek(0, System.IO.SeekOrigin.Begin);
//...
// Load the bar layout from a memory stream.
barManager1.RestoreLayoutFromStream(str);
str.Seek(0, System.IO.SeekOrigin.Begin);
vb
Dim str As System.IO.Stream
' Create and save the bar layout to a new memory stream.
str = New System.IO.MemoryStream()
BarManager1.SaveLayoutToStream(str)
str.Seek(0, System.IO.SeekOrigin.Begin)
' ..
' Load the bar layout from a memory stream.
BarManager1.RestoreLayoutFromStream(str)
str.Seek(0, System.IO.SeekOrigin.Begin)

See Also

Save/Restore Control Layout