Back to Devexpress

PivotGridControl.RestoreLayoutFromStream(Stream) Method

wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridcontrol-dot-restorelayoutfromstream-x28-system-dot-io-dot-stream-x29.md

latest6.5 KB
Original Source

PivotGridControl.RestoreLayoutFromStream(Stream) Method

SECURITY-RELATED CONSIDERATIONS

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

Restores the pivot grid layout from the specified stream.

Namespace : DevExpress.Xpf.PivotGrid

Assembly : DevExpress.Xpf.PivotGrid.v25.2.dll

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

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

Parameters

NameTypeDescription
streamStream

A Stream descendant that stores the pivot grid’s layout.

|

Remarks

To save the pivot grid layout, use the PivotGridControl.SaveLayoutToStream method.

Note that you should specify unique names for all pivot grid fields to correctly save and restore the layout. You can do this using the PivotGridField.Name property.

To learn more, see Save and Restore Layout.

Example

The following example shows how to save a PivotGridControl layout to a stream using the PivotGridControl.SaveLayoutToStream method and then, how to restore the layout from the stream using the PivotGridControl.RestoreLayoutFromStream method.

xaml
<Window xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"  
        x:Class="HowToSaveAndRestoreLayoutFromStream.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="380" Width="525" 
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" 
        xmlns:my="clr-namespace:HowToSaveAndRestoreLayoutFromStream.nwindDataSetTableAdapters" 
        xmlns:my1="clr-namespace:HowToSaveAndRestoreLayoutFromStream">
    <Window.Resources>
        <dx:TypedSimpleSource x:Key="TypedSimpleSource" 
                              AdapterType="my:SalesPersonTableAdapter" 
                              ContextType="my1:nwindDataSet" Path="SalesPerson">
            <dx:DesignDataManager.DesignData>
                <dx:DesignDataSettings RowCount="5" />
            </dx:DesignDataManager.DesignData>
        </dx:TypedSimpleSource>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <dxpg:PivotGridControl HorizontalAlignment="Left" Name="pivotGridControl1" 
                               VerticalAlignment="Top" 
                           DataSource="{Binding Path=Data, Source={StaticResource TypedSimpleSource}}">
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField Name="fieldCategory" FieldName="CategoryName" 
                                     Caption="Category" Area="RowArea" />
                <dxpg:PivotGridField Name="fieldYear" FieldName="OrderDate" Area="ColumnArea" 
                                     Caption="Year" GroupInterval="DateYear" />
                <dxpg:PivotGridField Name="fieldExtendedPrice" FieldName="Extended Price" 
                                     Area="DataArea" CellFormat="c0"/>
            </dxpg:PivotGridControl.Fields>
        </dxpg:PivotGridControl>
        <StackPanel Grid.Row="1" Orientation="Horizontal">
            <Button Name="buttonSave" Content="Save" Padding="8, 4, 8, 4" 
                    Margin="4" Click="buttonSave_Click" ></Button>
            <Button Name="buttonLoad" Content="Load" Padding="8, 4, 8, 4" 
                    Margin="4" Click="buttonLoad_Click"></Button>
        </StackPanel>
    </Grid>
</Window>
vb
Imports System.Windows

Namespace HowToSaveAndRestoreLayoutFromStream
    Partial Public Class MainWindow
        Inherits Window

        ' Create a MemoryStream instance.
        Private LayoutStream As System.IO.Stream = New System.IO.MemoryStream()

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub buttonSave_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
            ' Save the layout to a stream.
            pivotGridControl1.SaveLayoutToStream(LayoutStream)
        End Sub

        Private Sub buttonLoad_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
            LayoutStream.Position = 0
            ' Load the layout from the stream.
            pivotGridControl1.RestoreLayoutFromStream(LayoutStream)
        End Sub
    End Class
End Namespace
csharp
using System.Windows;

namespace HowToSaveAndRestoreLayoutFromStream {
    public partial class MainWindow : Window {
        // Create a MemoryStream instance.
        System.IO.Stream LayoutStream = new System.IO.MemoryStream();
        public MainWindow() {
            InitializeComponent();
        }
        private void buttonSave_Click(object sender, RoutedEventArgs e) {
            // Save the layout to a stream.
            pivotGridControl1.SaveLayoutToStream(LayoutStream);
        }
        private void buttonLoad_Click(object sender, RoutedEventArgs e) {
            LayoutStream.Position = 0;
            // Load the layout from the stream.
            pivotGridControl1.RestoreLayoutFromStream(LayoutStream);
        }
    }
}

See Also

PivotGridControl Class

PivotGridControl Members

DevExpress.Xpf.PivotGrid Namespace