How to: Select Properties to be Saved when Saving the Grid Layout

  • 4 minutes to read

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 &amp; 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>