The following example shows how to specify which properties should be saved/restored when saving/restoring the layout of a control.In this example, the DXSerializer.AllowPropertyEvent attached event is handled to specify which properties of the DXGrid columns should be saved when saving the grid layout. The event parameter's Allow property is set to true for three properties: GridColumn.ActualWidth, GridColumn.FieldName and GridColumn.Visible. Thus, these properties are saved for every grid column
<Window x:Class="SelectingPropertiesToSerialize.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" Title="Save & Restore Layout" Height="236" Width="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="165" />
<RowDefinition />
</Grid.RowDefinitions>
<dxg:GridControl Name="gridControl1" Loaded="gridControl1_Loaded">
<dxg:GridControl.Columns>
<dxg:GridColumn x:Name="colIssueName" FieldName="IssueName" Visible="True" Width="100" />
<dxg:GridColumn x:Name="colIssueType" FieldName="IssueType" Visible="True" Width="80" />
<dxg:GridColumn x:Name="colPrivate" FieldName="IsPrivate" Visible="False" Width="20">Private</dxg:GridColumn>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True" />
</dxg:GridControl.View>
</dxg:GridControl>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Grid.Row="1" Margin="0,5,0,0">
<Button x:Name="btnSaveLayout" Margin="5,0,5,0" Height="22" Width="90" Click="btnSaveLayout_Click">Save Layout</Button>
<Button x:Name="btnRestoreLayout" Margin="5,0,5,0" Height="22" Width="90" Click="btnRestoreLayout_Click">Restore Layout</Button>
</StackPanel>
</Grid>
</Window>
using System.Collections.Generic;
using System.Windows;
using DevExpress.Xpf.Core.Serialization;
using DevExpress.Xpf.Grid;
namespace SelectingPropertiesToSerialize {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
}
private void gridControl1_Loaded(object sender, RoutedEventArgs e) {
gridControl1.ItemsSource = IssueList.GetData();
foreach (GridColumn column in gridControl1.Columns)
column.AddHandler(DXSerializer.AllowPropertyEvent,
new AllowPropertyEventHandler(column_AllowProperty));
}
void column_AllowProperty(object sender, AllowPropertyEventArgs e) {
e.Allow = e.DependencyProperty == GridColumn.ActualWidthProperty ||
e.DependencyProperty == GridColumn.FieldNameProperty ||
e.DependencyProperty == GridColumn.VisibleProperty;
}
public class IssueList {
static public List<IssueDataObject> GetData() {
List<IssueDataObject> data = new List<IssueDataObject>();
data.Add(new IssueDataObject() { IssueName = "Transaction History", IssueType = "Bug", IsPrivate = true });
data.Add(new IssueDataObject() { IssueName = "Ledger: Inconsistency", IssueType = "Bug", IsPrivate = false });
data.Add(new IssueDataObject() { IssueName = "Data Import", IssueType = "Request", IsPrivate = false });
data.Add(new IssueDataObject() { IssueName = "Data Archiving", IssueType = "Request", IsPrivate = true });
return data;
}
}
public class IssueDataObject {
public string IssueName { get; set; }
public string IssueType { get; set; }
public bool IsPrivate { get; set; }
}
private void btnRestoreLayout_Click(object sender, RoutedEventArgs e) {
gridControl1.RestoreLayoutFromXml("layout.xml");
}
private void btnSaveLayout_Click(object sender, RoutedEventArgs e) {
gridControl1.SaveLayoutToXml("layout.xml");
}
}
}
<Application x:Class="SelectingPropertiesToSerialize.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="Window1.xaml">
<Application.Resources>
</Application.Resources>
</Application>
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Windows
Imports DevExpress.Xpf.Core.Serialization
Imports DevExpress.Xpf.Grid
Namespace SelectingPropertiesToSerialize
Partial Public Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub gridControl1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
gridControl1.ItemsSource = IssueList.GetData()
For Each column As GridColumn In gridControl1.Columns
column.AddHandler(DXSerializer.AllowPropertyEvent, New AllowPropertyEventHandler(AddressOf column_AllowProperty))
Next column
End Sub
Private Sub column_AllowProperty(ByVal sender As Object, ByVal e As AllowPropertyEventArgs)
e.Allow = e.DependencyProperty Is GridColumn.ActualWidthProperty OrElse e.DependencyProperty Is GridColumn.FieldNameProperty OrElse e.DependencyProperty Is GridColumn.VisibleProperty
End Sub
Public Class IssueList
Public Shared Function GetData() As List(Of IssueDataObject)
Dim data As New List(Of IssueDataObject)()
data.Add(New IssueDataObject() With {.IssueName = "Transaction History", .IssueType = "Bug", .IsPrivate = True})
data.Add(New IssueDataObject() With {.IssueName = "Ledger: Inconsistency", .IssueType = "Bug", .IsPrivate = False})
data.Add(New IssueDataObject() With {.IssueName = "Data Import", .IssueType = "Request", .IsPrivate = False})
data.Add(New IssueDataObject() With {.IssueName = "Data Archiving", .IssueType = "Request", .IsPrivate = True})
Return data
End Function
End Class
Public Class IssueDataObject
Private privateIssueName As String
Public Property IssueName() As String
Get
Return privateIssueName
End Get
Set(ByVal value As String)
privateIssueName = value
End Set
End Property
Private privateIssueType As String
Public Property IssueType() As String
Get
Return privateIssueType
End Get
Set(ByVal value As String)
privateIssueType = value
End Set
End Property
Private privateIsPrivate As Boolean
Public Property IsPrivate() As Boolean
Get
Return privateIsPrivate
End Get
Set(ByVal value As Boolean)
privateIsPrivate = value
End Set
End Property
End Class
Private Sub btnRestoreLayout_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
gridControl1.RestoreLayoutFromXml("layout.xml")
End Sub
Private Sub btnSaveLayout_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
gridControl1.SaveLayoutToXml("layout.xml")
End Sub
End Class
End Namespace
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Windows
Namespace SelectingPropertiesToSerialize
''' <summary>
''' Interaction logic for App.xaml
''' </summary>
Partial Public Class App
Inherits Application
End Class
End Namespace