Infragistics® WPF 2016.1
Getting Started with Infragistics Control Persistence Framework

Before You Begin

The main purpose of the Infragistics Control Persistence Framework is to provide a unified API that allows you to save and load a control’s state. You can store a single control’s settings or the settings of multiple controls when using groups.

What You Will Accomplish

This topic will walk you through how to get started with the Infragistics Control Persistence Framework. You will implement functionality for saving and loading the xamDialogWindow control settings. These settings will be stored in isolated storage.

Follow these Steps

  1. Create a Microsoft® WPF™ project
  2. In the Solution Explorer, add the following references to your project:

    InfragisticsWPF4.v16.1.dll

    InfragisticsWPF4.Persistence.v16.1.dll

    InfragisticsWPF4.Controls.Interactions.XamDialogWindow.v16.1.dll

  3. Add the following namespace

    In XAML:

    xmlns:ig="http://schemas.infragistics.com/xaml"
    
  4. There is a xamDialogWindow control and two buttons on the page. The controls are placed into two rows of a Grid container.

    In XAML:

    <Grid x:Name="LayoutRoot">
       <Grid.RowDefinitions>
          <RowDefinition Height="*" />
          <RowDefinition Height="Auto" />
    </Grid.RowDefinitions> <!-- Add more elements --> </Grid>
  5. Add the xamDialogWindow control 

    In XAML:

    <ig:XamDialogWindow x:Name="myDialog" Height="200" Width="300"   
    IsMoveable="True" IsResizable="True" RestrictInContainer="True"
    StartupPosition="Center" Grid.Row="0" />
  6. Add the two buttons in the StackPanel container

    In XAML:

    <StackPanel Orientation="Horizontal" Grid.Row="1">
        <Button x:Name="BtnSave" Click="BtnSave_Click" Height="22" 
    Width="100" Content="Save" /> <Button x:Name="BtnLoad" Click="BtnLoad_Click" Height="22"
    Width="100" Content="Load" /> </StackPanel>
  7. Add the following using/Import directives so that you don’t have to type out a member’s fully qualified name.

    In Visual Basic:

    Imports System.IO
    Imports System.IO.IsolatedStorage
    Imports Infragistics
    Imports Infragistics.Controls.Interactions
    Imports Infragistics.Persistence

    In C#:

    using System.IO;
    using System.IO.IsolatedStorage; 
    using Infragistics;
    using Infragistics.Controls.Interactions;
    using Infragistics.Persistence;
  8. In the code behind, add functionality to save the xamDialogWindow control’s properties and to handle BtnSave_Click event.

    In Visual Basic:

    Private fileName As String = "tempFile"
    Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    ' Save xamDialogWindow settings into a MemoryStream
    Dim memoryStream As MemoryStream = PersistenceManager.Save(myDialog)
    ' Obtains user-scoped isolated storage for use by an application
    Using iso As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
        If iso.FileExists(fileName) Then
            iso.DeleteFile(fileName)
        End If
        Using stream As New IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, iso)
           ' Write file in the isolated storage
           stream.Write(memoryStream.ToArray(),0,CInt(memoryStream.Length))
        End Using
    End Using
    End Sub
    

    In C#:

    private const string fileName = "tempFile";
    private void BtnSave_Click(object sender, RoutedEventArgs e)
    {
       // Save xamDialogWindow settings into a MemoryStream
       MemoryStream memoryStream = PersistenceManager.Save(myDialog);
       // Obtains user-scoped isolated storage for use by an application
       using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
       {
          if (iso.FileExists(fileName))
             iso.DeleteFile(fileName);
    
          using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, iso))
          {
             // Write file in the isolated storage
             stream.Write(memoryStream.ToArray(), 0, (int)memoryStream.Length);
          }
       }
    }
    
  9. Add functionality to load the xamDialogWindow control’s properties and to handle the BtnLoad_Click event.

    In Visual Basic:

    Private Sub BtnLoad_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Using iso As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
        If iso.FileExists(fileName) Then
            Using stream As New IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, iso)
                PersistenceManager.Load(myDialog, stream)
            End Using
        End If
    End Using
    End Sub
    

    In C#:

    private void BtnLoad_Click(object sender, RoutedEventArgs e)
    {
        using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (iso.FileExists(fileName))
            {
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, iso))
                {
                    PersistenceManager.Load(myDialog, stream);
                }
            }   
        }
    }
    
  10. Save and run your application. You can save the xamDialogWindow properties by pressing the Save button; afterwards, you can resize and/or move the xamDialogWindow and click the Load button to restore the previous state of the control.

Related Topics

About Infragistics Control Persistence Framework

Using Infragistics Control Persistence Framework

 

 


Copyright © 2008-2016 Infragistics, Inc. All rights reserved.

E-mail your feedback on this topic.