Xceed DataGrid for WPF v7.2 Documentation
SaveUserSettings Method
Example 


Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace > DataGridControl Class : SaveUserSettings Method
A reference to a SettingsRepository to which the settings are to be persisted.
A UserSettings value representing the settings that are to be saved.
Saves the settings to a settings repository.
Syntax
'Declaration
 
Public Sub SaveUserSettings( _
   ByVal settingsRepository As SettingsRepository, _
   ByVal settings As UserSettings _
) 
'Usage
 
Dim instance As DataGridControl
Dim settingsRepository As SettingsRepository
Dim settings As UserSettings
 
instance.SaveUserSettings(settingsRepository, settings)
public void SaveUserSettings( 
   SettingsRepository settingsRepository,
   UserSettings settings
)

Parameters

settingsRepository
A reference to a SettingsRepository to which the settings are to be persisted.
settings
A UserSettings value representing the settings that are to be saved.
Example

All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.

The following example demonstrates how to persist and load settings using an XML serializer.The following code provides the implementation required to persist and load settings using the XmlSerializer class. The following code provides the implementation required to persist and load settings using the XmlSerializer class.
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
  <Grid.Resources>
     <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                        Source="{Binding Source={x:Static Application.Current}, Path=Orders}" />

  </Grid.Resources>
  <DockPanel>
     <StackPanel Orientation="Horizontal"
                 DockPanel.Dock="Top">
        <Button Content="Save Settings"
                Click="SaveSettings" />
        <Button Content="Load Settings"
                Click="LoadSettings" />
     </StackPanel>
     <xcdg:DataGridControl x:Name="OrdersGrid"
        ItemsSource="{Binding Source={StaticResource cvs_orders}}">
     </xcdg:DataGridControl>
  </DockPanel>
</Grid>
Private Sub SaveSettings( ByVal sender As Object, ByVal e As RoutedEventArgs )


  Dim settings As New SettingsRepository()
  Me.OrdersGrid.SaveUserSettings( settings, UserSettings.All )

  Dim serializer As New XmlSerializer( GetType( SettingsRepository ) )

  Using stream As New FileStream( "d:\settings.xml", FileMode.CreateNew )
    serializer.Serialize( stream, settings )
  End Using
End Sub

Private Sub LoadSettings( ByVal sender As Object, ByVal e As RoutedEventArgs )


  Dim settings As SettingsRespository

  Using stream As New FileStream( "d:\settings.xml", FileMode.Open )
    Dim serializer As New XmlSerializer( GetType( SettingsRepository ) )
    settings = TryCast( serializer.Deserialize( stream ), SettingsRepository )
  End Using

  Me.OrdersGrid.LoadUserSettings( settings, UserSettings.All )
End Sub
private void SaveSettings( object sender, RoutedEventArgs e )
{


 SettingsRepository settings = new SettingsRepository();   
 this.OrdersGrid.SaveUserSettings( settings, UserSettings.All );

 XmlSerializer serializer = new XmlSerializer( typeof( SettingsRepository ) );

 using( FileStream stream = new FileStream( "d:\\settings.xml", FileMode.CreateNew ) )
 {
   serializer.Serialize( stream, settings );
 }
}

private void LoadSettings( object sender, RoutedEventArgs e )
{


 SettingsRepository settings;
 using( FileStream stream = new FileStream( "d:\\settings.xml", FileMode.Open ) )
 {
   XmlSerializer serializer = new XmlSerializer( typeof( SettingsRepository ) );
   settings = serializer.Deserialize( stream ) as SettingsRepository;
 }

 this.OrdersGrid.LoadUserSettings( settings, UserSettings.All );
}
Requirements

See Also

Reference

DataGridControl Class
DataGridControl Members
LoadUserSettings Method

DataGrid Fundamentals

Persisting Settings