Isolated Storage

The PersistenceFramework allows you to save the layout of UIElements in an isolated storage. For that purpose the telerik:PersistenceManager.StorageId attached property has to be set for each UIElement that will 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.

<Grid x:Name="LayoutRoot" Background="White"> 
        <ColumnDefinition Width="" /> 
        <ColumnDefinition Width="" /> 
        <RowDefinition Height="" /> 
        <RowDefinition Height="Auto" /> 
    <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 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 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" /> 
    <StackPanel Orientation="Horizontal" Grid.Row="1"> 
        <Button Content="Save" Click="Save" VerticalAlignment="Bottom" FontWeight="Bold" /> 
        <Button Content="Load" Click="Load" VerticalAlignment="Bottom" FontWeight="Bold" /> 
    <Border Grid.Column="1" BorderBrush="Blue" BorderThickness="1"> 
        <ContentControl HorizontalContentAlignment="Stretch" telerik:PersistenceManager.StorageId="detailsControl"> 
                    <ColumnDefinition Width="Auto" /> 
                    <ColumnDefinition Width="" /> 
                    <RowDefinition Height="Auto" /> 
                    <RowDefinition Height="Auto" /> 
                <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" /> 
In order to save the persisted properties in an isolated storage, you can use the IsolatedStorageProvider. It exposes the following members:
  • SaveToStorage() - the method that saves the UIElement properties in the associated file in the isolated storage

  • LoadFromStorage() - the method that loads the persisted properties from the UIElement's associated file

  • QuotaRequested - is an 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 filestreams 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

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.

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

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

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

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

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

In this article
Not finding the help you need? Improve this article