Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DataControlBase.RestoreLayoutFromStream(Stream) Method

SECURITY NOTE

Deserializing layout settings from untrusted resources may create security issues. Review the following help topic for additional information: Safe Deserialization.

Restores a control’s layout from the specified stream.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v24.2.Core.dll

NuGet Package: DevExpress.Wpf.Grid.Core

#Declaration

public void RestoreLayoutFromStream(
    Stream stream
)

#Parameters

Name Type Description
stream Stream

A Stream descendant that stores the a control’s layout.

#Remarks

To save a control’s layout to a stream, use the DataControlBase.SaveLayoutToStream method.

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.

#Example

This example shows how to save the GridControl‘s layout to a memory stream. To do this, click the Save Layout button. Click the Restore Layout button to restore the saved layout.

Serialize the WPF Grid

View Example: Save Layout and Restore It from a Memory Stream

<dxg:GridControl x:Name="grid"
                 dx:DXSerializer.StoreLayoutMode="All" 
                 dxg:GridSerializationOptions.AddNewColumns="False" 
                 dxg:GridSerializationOptions.RemoveOldColumns="False"
                 UseFieldNameForSerialization="True">
    <dxg:GridColumn FieldName="IssueName"/>
    <dxg:GridColumn FieldName="IssueType"/>
    <dxg:GridColumn FieldName="IsPrivate" Header="Private"/>
    <dxg:GridControl.View>
        <dxg:TableView AutoWidth="True"/>
    </dxg:GridControl.View>
</dxg:GridControl>

<StackPanel Grid.Row="1" Orientation="Vertical">
    <StackPanel Orientation="Horizontal">
        <Button Margin="1" Content="Add a New Column" Click="OnAddNewColumn"/>
    </StackPanel>
    <StackPanel Orientation="Horizontal">
        <Button Content="Save Layout" Margin="1" Click="OnSaveLayout"/>
        <Button Content="Restore Layout" Margin="1" Click="OnRestoreLayout"/>
    </StackPanel>
</StackPanel>
public partial class Window1 : Window {
    MemoryStream layoutStream;
    public Window1() {
        InitializeComponent();
        grid.ItemsSource = IssueList.GetData();
    }

    void OnSaveLayout(object sender, RoutedEventArgs e) {
        layoutStream = new MemoryStream();
        grid.SaveLayoutToStream(layoutStream);
    }
    void OnRestoreLayout(object sender, RoutedEventArgs e) {
        layoutStream.Position = 0;
        grid.RestoreLayoutFromStream(layoutStream);
    }
    void OnAddNewColumn(object sender, RoutedEventArgs e) {
        grid.Columns.Add(new DevExpress.Xpf.Grid.GridColumn() { FieldName = "IsPrivate" });
    }
}
See Also