Back to Devexpress

DataControlBase.SaveLayoutToStream(Stream) Method

wpf-devexpress-dot-xpf-dot-grid-dot-datacontrolbase-dot-savelayouttostream-x28-system-dot-io-dot-stream-x29.md

latest6.1 KB
Original Source

DataControlBase.SaveLayoutToStream(Stream) Method

Saves a control’s layout to the specified stream.

Namespace : DevExpress.Xpf.Grid

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

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public void SaveLayoutToStream(
    Stream stream
)
vb
Public Sub SaveLayoutToStream(
    stream As Stream
)

Parameters

NameTypeDescription
streamStream

A Stream descendant to which a control’s layout is written.

|

Remarks

To restore a control’s layout previously saved by the SaveLayoutToStream method, use the DataControlBase.RestoreLayoutFromStream 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.

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

xaml
<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>
cs
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" });
    }
}
vb
Public Partial Class Window1
    Inherits Window

    Private layoutStream As MemoryStream

    Public Sub New()
        Me.InitializeComponent()
        Me.grid.ItemsSource = IssueList.GetData()
    End Sub

    Private Sub OnSaveLayout(ByVal sender As Object, ByVal e As RoutedEventArgs)
        layoutStream = New MemoryStream()
        Me.grid.SaveLayoutToStream(layoutStream)
    End Sub

    Private Sub OnRestoreLayout(ByVal sender As Object, ByVal e As RoutedEventArgs)
        layoutStream.Position = 0
        Me.grid.RestoreLayoutFromStream(layoutStream)
    End Sub

    Private Sub OnAddNewColumn(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Me.grid.Columns.Add(New DevExpress.Xpf.Grid.GridColumn() With {.FieldName = "IsPrivate"})
    End Sub
End Class

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SaveLayoutToStream(Stream) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-data-grid-save-layout-and-restore-it-from-memory-stream/CS/DXGrid_GridLayout/Window1.xaml.cs#L15

csharp
layoutStream = new MemoryStream();
    grid.SaveLayoutToStream(layoutStream);
}

wpf-data-grid-save-layout-and-restore-it-from-memory-stream/VB/DXGrid_GridLayout/Window1.xaml.vb#L19

vb
layoutStream = New MemoryStream()
    Me.grid.SaveLayoutToStream(layoutStream)
End Sub

See Also

SaveLayoutToXml(String)

DataControlBase Class

DataControlBase Members

DevExpress.Xpf.Grid Namespace