DataControlBase.RestoreLayoutFromXml(String) Method

Restores a control's layout from the specified XML file.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v20.1.Core.dll

Declaration

public void RestoreLayoutFromXml(
    string path
)
Public Sub RestoreLayoutFromXml(
    path As String
)

Parameters

Name Type Description
path String

A String value that specifies the target file name.

Remarks

To save a control's layout to an XML file, use the DataControlBase.SaveLayoutToXml

NOTE

Detail grids aren't automatically serialized when saving the master grid's layout. To learn more, see Master-Detail Mode Limitations.

To learn more, see Saving and Restoring Layout.

Examples

This example shows how to save the grid layout to a memory stream. To do this, click the 'Save Layout' button. Once saved, the grid layout can then be restored by clicking the 'Restore Layout' button.

<UserControl x:Class="DXGrid_GridLayout.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400"
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" 
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" 
    xmlns:local="clr-namespace:DXGrid_GridLayout" >

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <dxg:GridControl x:Name="grid" dx:DXSerializer.SerializationID="grid" 
                         dx:DXSerializer.StoreLayoutMode="All" 
                         dxg:GridSerializationOptions.AddNewColumns="False" 
                         dxg:GridSerializationOptions.RemoveOldColumns="False">
            <dxg:GridControl.Columns>
                <dxg:GridColumn x:Name="colIssueName" FieldName="IssueName" />
                <dxg:GridColumn x:Name="colIssueType" FieldName="IssueType" />
                <dxg:GridColumn x:Name="colPrivate" FieldName="IsPrivate">Private</dxg:GridColumn>
            </dxg:GridControl.Columns>
            <dxg:GridControl.View>
                <dxg:TableView AutoWidth="True" />
            </dxg:GridControl.View>
        </dxg:GridControl>

        <StackPanel Grid.Row="1" Orientation="Vertical">
            <StackPanel Orientation="Horizontal">
                <Button Margin="1" Click="Button_Click">AddNewColumn</Button>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Button Margin="1" Click="SaveButton_Click">Save Layout</Button>
                <Button x:Name="restoreButton" Margin="1" 
                        Click="LoadButton_Click" IsEnabled="{Binding IsLayoutSaved}">
                        Restore Layout
                </Button>
            </StackPanel>
        </StackPanel>
    </Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;

namespace DXGrid_GridLayout {
    public partial class MainPage : UserControl {
        public static readonly DependencyProperty IsLayoutSavedProperty =
            DependencyProperty.Register("IsLayoutSaved", typeof(bool), typeof(MainPage), null);
        public bool IsLayoutSaved {
            get { return (bool)GetValue(IsLayoutSavedProperty); }
            set { SetValue(IsLayoutSavedProperty, value); }
        }
        MemoryStream layoutStream;
        public MainPage() {
            DataContext = this;
            InitializeComponent();
            IsLayoutSaved = false;
            grid.ItemsSource = IssueList.GetData();
        }

        private void SaveButton_Click(object sender, RoutedEventArgs e) {
            layoutStream = new MemoryStream();
            grid.SaveLayoutToStream(layoutStream);
            IsLayoutSaved = true;
        }
        private void LoadButton_Click(object sender, RoutedEventArgs e) {
            layoutStream.Position = 0;
            grid.RestoreLayoutFromStream(layoutStream);
        }
        private void Button_Click(object sender, RoutedEventArgs e) {
            grid.Columns.Add(new DevExpress.Xpf.Grid.GridColumn() { FieldName = "IsPrivate" });
        }
    }
    public class IssueList {
        static public List<IssueDataObject> GetData() {
            List<IssueDataObject> data = new List<IssueDataObject>();
            data.Add(new IssueDataObject() {
                IssueName = "Transaction History",
                IssueType = "Bug", IsPrivate = true
            });
            data.Add(new IssueDataObject() {
                IssueName = "Ledger: Inconsistency",
                IssueType = "Bug", IsPrivate = false
            });
            data.Add(new IssueDataObject() {
                IssueName = "Data Import",
                IssueType = "Request", IsPrivate = false
            });
            data.Add(new IssueDataObject() {
                IssueName = "Data Archiving",
                IssueType = "Request", IsPrivate = true
            });
            return data;
        }
    }

    public class IssueDataObject {
        public string IssueName { get; set; }
        public string IssueType { get; set; }
        public bool IsPrivate { get; set; }
    }
}
See Also