Isolated Storage

The PersistenceFramework allows you to save the layout of UIElements in Isolated Storage. For that purpose the telerik:PersistenceManager.StorageId attached property has to be set for each UIElement that needs to be persisted. The property is used to create a file in the isolated storage for each persisted control, where the control's properties will be kept.

Example 1: Setting the PersistenceManager.StorageId property

<Grid x:Name="LayoutRoot" Background="White"> 
    <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="" /> 
        <ColumnDefinition Width="" /> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
        <RowDefinition Height="" /> 
        <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <telerik:RadTreeView x:Name="treeView" telerik:PersistenceManager.StorageId="treeView"> 
        <telerik:RadTreeViewItem Header="Beverages"> 
            <telerik:RadTreeViewItem Header="Chai" /> 
            <telerik:RadTreeViewItem Header="Chang" /> 
            <telerik:RadTreeViewItem Header="Ipoh Coffee" /> 
            <telerik:RadTreeViewItem Header="Chartreuse verte" /> 
            <telerik:RadTreeViewItem Header="Sasquatch Ale" /> 
        </telerik:RadTreeViewItem> 
        <telerik:RadTreeViewItem Header="Condiments"> 
            <telerik:RadTreeViewItem Header="Aniseed Syrup" /> 
            <telerik:RadTreeViewItem Header="Genen Shouyu" /> 
            <telerik:RadTreeViewItem Header="Gula Malacca" /> 
            <telerik:RadTreeViewItem Header="Louisiana Hot Spiced Okra" /> 
            <telerik:RadTreeViewItem Header="Louisiana Fiery Hot Pepper Sauce" /> 
        </telerik:RadTreeViewItem> 
        <telerik:RadTreeViewItem Header="Confections"> 
            <telerik:RadTreeViewItem Header="Teatime Chocolate Biscuits" /> 
            <telerik:RadTreeViewItem Header="Sir Rodney's Marmalade" /> 
            <telerik:RadTreeViewItem Header="Zaanse koeken" /> 
            <telerik:RadTreeViewItem Header="Chocolade" /> 
            <telerik:RadTreeViewItem Header="Maxilaku" /> 
            <telerik:RadTreeViewItem Header="Valkoinen suklaa" /> 
        </telerik:RadTreeViewItem> 
    </telerik:RadTreeView> 
    <StackPanel Orientation="Horizontal" Grid.Row="1"> 
        <Button Content="Save" Click="Save" VerticalAlignment="Bottom" FontWeight="Bold" /> 
        <Button Content="Load" Click="Load" VerticalAlignment="Bottom" FontWeight="Bold" /> 
    </StackPanel> 
    <Border Grid.Column="1" BorderBrush="Blue" BorderThickness="1"> 
        <ContentControl HorizontalContentAlignment="Stretch" telerik:PersistenceManager.StorageId="detailsControl"> 
            <Grid> 
                <Grid.ColumnDefinitions> 
                    <ColumnDefinition Width="Auto" /> 
                    <ColumnDefinition Width="" /> 
                </Grid.ColumnDefinitions> 
                <Grid.RowDefinitions> 
                    <RowDefinition Height="Auto" /> 
                    <RowDefinition Height="Auto" /> 
                </Grid.RowDefinitions> 
                <TextBlock Text="Details" Margin="2" VerticalAlignment="Center" FontWeight="Bold" 
                        Grid.ColumnSpan="2" /> 
                <TextBlock Text="Add Description:" Grid.Row="1" Margin="2" VerticalAlignment="Center" /> 
                <TextBox Margin="2" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" 
                        HorizontalAlignment="Stretch" /> 
            </Grid> 
        </ContentControl> 
    </Border> 
</Grid> 

Example 2: Using the IsolatedStorageProvider methods

private void Save(object sender, RoutedEventArgs e) 
{ 
    IsolatedStorageProvider isoProvider = new IsolatedStorageProvider(); 
    isoProvider.SaveToStorage(); 
} 
private void Load(object sender, RoutedEventArgs e) 
{ 
    IsolatedStorageProvider isoProvider = new IsolatedStorageProvider(); 
    isoProvider.LoadFromStorage(); 
} 
Private Sub Save(sender As Object, e As RoutedEventArgs) 
    Dim isoProvider As New IsolatedStorageProvider() 
    isoProvider.SaveToStorage() 
End Sub 
Private Sub Load(sender As Object, e As RoutedEventArgs) 
    Dim isoProvider As New IsolatedStorageProvider() 
    isoProvider.LoadFromStorage() 
End Sub 

The IsolatedStorageProvider.SaveToStorage() method will save the properties of all controls for which the telerik:PersistenceManager.StorageId attached property is set. In Example 2 all properties of the RadTreeView and the ContentControl will be saved:

Figure 1: Result from Example 1

Using the IsolatedStorageProvider

  1. Expand Condiments and select Gula Malacca. Add description for the item in the Details ContentControl. Then hit Save: Saving the layout with the IsolatedStorageProvider

  2. Now change the layout of the UserControl - for example collapse Condiments and expand Confections. Then Select Maxilaku and add description for it. Changing the layout

  3. If you want to retrieve the previous state of the controls in your page, all you need to do is hit Load: Loading the layout with the IsolatedStorageProvider

IsolatedStorageProvider Members

The IsolatedStorageProvider exposes the following members:

  • SaveToStorage(): Saves the UIElement properties in the associated file in the isolated storage.

  • LoadFromStorage(): Loads the persisted properties from the UIElement's associated file.

  • DeleteIsolatedStorageFiles(): Deletes the saved isolated storage files.

  • QuotaRequested event: When the application requests a larger quota from the isolated storage, the user is prompted to allow or deny the request. The QuotaRequested event is fired when the user makes a choice. The event receives two arguments:

    • A sender argument that receives the IsolatedStorageProvider that is requesting the additional quota.
    • A QuotaRequestedEventArgs object that gives access to:
      • FileStreams: A dictionary that contains the names of the isolated storage files as keys, and the file streams as values.
      • IsSuccess: A property of type bool that indicates whether the user has allowed the quota increase.
      • RequestedBytes - A property of type long that represents the size of the requested quota.
  • Manager: A protected property, which exposes the PersistenceManager instance used by the class. You can inherit the IsolatedStorageProvider in order to access it.

  • GetIsolatedStoreOverride(): A protected method, which returns an IsolatedStorageFile. It allows you to work with the physical representation of the isolated storage files. You can inherit the IsolatedStorageProvider in order to access it.

When you are using the IsolatedStorageProvider, you can check the persistence storage and the controls that are persisted using the PersistenceManager.GetStorage() static method. It returns an object of type ObjectStorage that exposes the following properties:

  • Count: This property is of type int and it gets the number of persisted objects.
  • Items: This property gets the collection of persisted objects.
  • Keys: This property gets the collection of the persisted objects' StorageId values.
In this article
Not finding the help you need? Improve this article