wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridcontrol-dot-restorelayoutfromxml-x28-system-dot-string-x29.md
Deserializing layout settings from untrusted resources may create security issues. Review the following help topic for additional information: Safe Deserialization.
Restores the pivot grid’s layout from the specified XML file.
Namespace : DevExpress.Xpf.PivotGrid
Assembly : DevExpress.Xpf.PivotGrid.v25.2.dll
NuGet Package : DevExpress.Wpf.PivotGrid
public void RestoreLayoutFromXml(
string fileName
)
Public Sub RestoreLayoutFromXml(
fileName As String
)
| Name | Type | Description |
|---|---|---|
| fileName | String |
A String value that specifies the target file name.
|
To save the pivot grid’s layout, use the PivotGridControl.SaveLayoutToXml 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.
The following example shows how to save the Pivot Grid’s layout to a file in XML format. The “Save” button calls the PivotGridControl.SaveLayoutToXml method. The “Load” button calls the PivotGridControl.RestoreLayoutFromXml method to restore the saved layout.
using System.Data;
using System.Data.OleDb;
using System.Windows;
using DevExpress.Xpf.PivotGrid;
using HowToBindToMDB.NwindDataSetTableAdapters;
namespace HowToBindToMDB {
public partial class MainWindow : Window {
NwindDataSet.SalesPersonDataTable salesPersonDataTable = new NwindDataSet.SalesPersonDataTable();
SalesPersonTableAdapter salesPersonDataAdapter = new SalesPersonTableAdapter();
public MainWindow() {
InitializeComponent();
pivotGridControl1.DataSource = salesPersonDataTable;
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
salesPersonDataAdapter.Fill(salesPersonDataTable);
}
private void buttonSave_Click(object sender, RoutedEventArgs e) {
pivotGridControl1.SaveLayoutToXml("layout.xml");
}
private void buttonLoad_Click(object sender, RoutedEventArgs e) {
pivotGridControl1.RestoreLayoutFromXml("layout.xml");
}
}
}
Imports System.Windows
Imports HowToBindToMDB.NwindDataSetTableAdapters
Namespace HowToBindToMDB
Public Partial Class MainWindow
Inherits Window
Private salesPersonDataTable As NwindDataSet.SalesPersonDataTable = New NwindDataSet.SalesPersonDataTable()
Private salesPersonDataAdapter As SalesPersonTableAdapter = New SalesPersonTableAdapter()
Public Sub New()
Me.InitializeComponent()
Me.pivotGridControl1.DataSource = salesPersonDataTable
End Sub
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
salesPersonDataAdapter.Fill(salesPersonDataTable)
End Sub
Private Sub buttonSave_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Me.pivotGridControl1.SaveLayoutToXml("layout.xml")
End Sub
Private Sub buttonLoad_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Me.pivotGridControl1.RestoreLayoutFromXml("layout.xml")
End Sub
End Class
End Namespace
<Window x:Class="HowToBindToMDB.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<dxpg:PivotGridControl Name="pivotGridControl1" DataProcessingEngine="Optimized">
<dxpg:PivotGridControl.Fields>
<dxpg:PivotGridField Name="fieldCategory" Caption="Category" Area="RowArea">
<dxpg:PivotGridField.DataBinding>
<dxpg:DataSourceColumnBinding ColumnName="CategoryName"/>
</dxpg:PivotGridField.DataBinding>
</dxpg:PivotGridField>
<dxpg:PivotGridField Name="fieldYear" Area="ColumnArea" Caption="Year">
<dxpg:PivotGridField.DataBinding>
<dxpg:DataSourceColumnBinding ColumnName="OrderDate" GroupInterval="DateYear"/>
</dxpg:PivotGridField.DataBinding>
</dxpg:PivotGridField>
<dxpg:PivotGridField Name="fieldExtendedPrice" Area="DataArea" CellFormat="c0">
<dxpg:PivotGridField.DataBinding>
<dxpg:DataSourceColumnBinding ColumnName="Extended Price"/>
</dxpg:PivotGridField.DataBinding>
</dxpg:PivotGridField>
</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 Name="buttonLoad" Content="Load" Padding="8, 4, 8, 4"
Margin="4" Click="buttonLoad_Click" />
</StackPanel>
</Grid>
</Window>
See Also