Saves the settings to a settings repository.
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 );
}
2025 © Xceed Software Inc.
4170 Grande-Allée, Suite 100, Greenfield Park, Qc J4V 3N2