Edit this page

Serialization Options

PersistenceManager SerializationOptions

The PersistenceManager allows you to specify which properties of the UIElements to be persisted. In order to take advantage of this feature you need to set the PersistenceManager.SerializationOptions property. It allows you to define:

  • PropertyNameMetadata - determines the UIElement properties to be persisted by the PersistenceManager

  • PropertyTypeMetadata - determines properties of what type to be persisted by the PersistenceManager

PropertyNameMetadata

The PropertyNameMetadata class exposes the following members:

  • Condition - this property allows you to define the condition under which the property will be persisted. It is a SerializationMetadataCondition enumeration and exposes the following members:

    • Only - states that only this property will be persisted.
    • Except - states that this property won't be persisted.
  • Expression - this property allows you to define a regular expression that will be evaluated against the value of the SearchType property.

  • IsRecursive - this property controls whether the Expression will be evaluated in depth.

  • SearchType - this property controls against what the Expression should be evaluated. It is a MetadataSearchCriteria enumeration that allows you to choose between the following values:

    • PropertyName - the Expression will be evaluated against a property name in the UIElement
    • PropertyPath - the Expression will be evaluated against the full path of the property (the path from the serialization root to the property)
  • ShouldSerialize() - this method evaluates the PropertyNameMetadata properties to decide whether a property should or shouldn't be persisted

PropertyTypeMetadata

The PropertyTypeMetadata class exposes the following members:

  • AllowSubclasses - determines whether properties of types that are sub-classes of the specified type should be persisted

  • Condition - this property allows you to define the condition under which the specified type of properties will be persisted. It is a SerializationMetadataCondition enumeration and exposes the following members:

    • Only - states that only this type of properties will be persisted;
    • Except - states that no property of the specified type will be persisted.
  • IsRecursive - this property controls whether an in-depth search for properties of the specified type should be implemented.

  • Type - defines the type of properties that should be persisted and is of type Type. This property cannot be set in XAML.

  • TypeString - is of type string and allows you to set the type of the properties that should be persisted in XAML.

  • ShouldSerialize() - this method evaluates the PropertyTypeMetadata properties to decide whether a property should or shouldn't be persisted

SerializationMetadataCollection

The PersistenceManager.SerializationOptions property is of type SerializationMetadataCollection. The SerializationMetadataCollection class is a collection of ISerializationMetadata and this is why it can be filled with PropertyTypeMetadata and PropertyNameMetadata items.

The SerializationMetadataCollection also exposes an Operator property that controls the relationship between its items. The Operator property is a LogicalOperator enumeration that exposes the following members:

  • And - a property should fulfill all conditions defined by the items in the SerializationMetadataCollection in order to be persisted

  • Or - if a property fulfills even one of the conditions defined by the SerializationMetadataCollection items, it will be persisted

The SerializationMetadataCollection class exposes the following methods:

  • ShouldSerialize() - the method evaluates each SerializationMetadataCollection item in order to determine which properties should be persisted.

For example in the RadTreeView definition we can define only the IsExpanded and IsSelected properties to be persisted:

XAML

<telerik:RadTreeView x:Name="treeView">
 <telerik:PersistenceManager.SerializationOptions>
  <telerik:SerializationMetadataCollection Operator="Or">
   <telerik:PropertyNameMetadata Condition="Only" Expression="IsSelected" SearchType="PropertyName" />
   <telerik:PropertyNameMetadata Condition="Only" Expression="IsExpanded" SearchType="PropertyName" />
  </telerik:SerializationMetadataCollection>
 </telerik:PersistenceManager.SerializationOptions>
 <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>

Or you can define all properties to be persisted except the IsSelected property:

XAML

<telerik:RadTreeView x:Name="treeView" >
 <telerik:PersistenceManager.SerializationOptions>
  <telerik:SerializationMetadataCollection>
   <telerik:PropertyNameMetadata Condition="Except" Expression="IsSelected" SearchType="PropertyName" />
  </telerik:SerializationMetadataCollection>
 </telerik:PersistenceManager.SerializationOptions>
...
</telerik:RadTreeView>