In This Topic
    In This Topic

    The following example demonstrates how to persist and load settings using the application settings. 

    XAML
    Copy Code
    <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>

    The following code provides the implementation required to persist and load settings using the application settings.

    VB.NET
    Copy Code
    Private Sub SaveSettings( ByVal sender As Object, ByVal e As RoutedEventArgs )
      If Xceed.Wpf.Documentation.Properties.Settings.Default.GridSettings Is Nothing Then
        Xceed.Wpf.Documentation.Properties.Settings.Default.GridSettings = New SettingsRepository()
      End If
      Me.OrdersGrid.SaveUserSettings( Xceed.Wpf.Documentation.Properties.Settings.Default.GridSettings, UserSettings.All )
    End Sub
    Private Sub LoadSettings( ByVal sender As Object, ByVal e As RoutedEventArgs )
      If Xceed.Wpf.Documentation.Properties.Settings.Default.GridSettings Is Nothing Then
        Return
      End If
      Me.OrdersGrid.LoadUserSettings( Xceed.Wpf.Documentation.Properties.Settings.Default.GridSettings, UserSettings.All )
    End Sub
    C#
    Copy Code
    private void SaveSettings( object sender, RoutedEventArgs e )
    {
     if( Xceed.Wpf.Documentation.Properties.Settings.Default.GridSettings == null )
     {
       Xceed.Wpf.Documentation.Properties.Settings.Default.GridSettings = new SettingsRepository();
     }
     this.OrdersGrid.SaveUserSettings( Xceed.Wpf.Documentation.Properties.Settings.Default.GridSettings, UserSettings.All );
    }
    private void LoadSettings( object sender, RoutedEventArgs e )
    {
     if( Xceed.Wpf.Documentation.Properties.Settings.Default.GridSettings == null )
       return;
     this.OrdersGrid.LoadUserSettings( Xceed.Wpf.Documentation.Properties.Settings.Default.GridSettings, UserSettings.All );
    }

    In addition to persisting and load the grid-specific settings to and from the resources, the application settings themselves must also be persisted using the default setting's Reload and Save methods, which are usually called in the application's OnStartup and OnExit overrides, respectively.

    VB.NET
    Copy Code
    Protected Overrides Sub OnStartup( ByVal e As StartupEventArgs )
      Xceed.Wpf.DataGrid.Licenser.LicenseKey = "license_key"
      MyBase.OnStartup( e )
      Settings.Default.Reload()
    End Sub
    Protected Override Sub OnExit( ByVal e As ExitEventArgs )
      Settings.Default.Save()
      MyBase.OnExit( e )
    End Sub
    C#
    Copy Code
    protected override void OnStartup( StartupEventArgs e )
    {
      Xceed.Wpf.DataGrid.Licenser.LicenseKey = "license_key";
      base.OnStartup( e ); 
      Settings.Default.Reload();
    }
    protected override void OnExit( ExitEventArgs e )
    { 
      Settings.Default.Save();
      base.OnExit( e );
    }