<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 );
}