How to: Save and restore layout of items in TileLayoutControl
The following example shows how to save the layout of items of a TileLayoutControl object to a stream, and then restore the layout. The LayoutControlBase.WriteToXML and LayoutControl.ReadFromXML methods are used to do this.
<Window ...
xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol">
<Grid>
<dxlc:TileLayoutControl Background="#FF0E6D38" x:Name="myLayoutControl">
<dxlc:Tile x:Name="tile1"/>
<dxlc:Tile x:Name="tile2"/>
<dxlc:Tile x:Name="tile3"/>
</dxlc:TileLayoutControl>
<Button Click="Button_Click_1"></Button>
<Button Click="Button_Click"></Button>
</Grid>
</Window>
using System.Xml;
using System.IO;
public partial class MainWindow : Window
{
MemoryStream stream = new MemoryStream();
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
XmlWriter writer = XmlWriter.Create(stream);
myLayoutControl.WriteToXML(writer);
writer.Close();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
stream.Seek(0, SeekOrigin.Begin);
XmlReader reader = XmlReader.Create(stream);
myLayoutControl.ReadFromXML(reader);
reader.Close();
}
}