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

How to: Save and Restore Layout to/from a Stream

  • 2 minutes to read

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.

<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>