Serialization Options

The PersistenceManager class 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 attached property. The property allows you to use the following element.

  • 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 as a base for a Regex that is applied over the property names of the object that is being serialized. The Expression property also takes into account the value of the SearchType property.

    Example 1: Using Expression to serialize only the Width property of a RadButton

         <telerik:RadButton> 
            <telerik:PersistenceManager.SerializationOptions> 
                <telerik:SerializationMetadataCollection> 
                    <telerik:PropertyNameMetadata Condition="Only" Expression="^\b(Width)\b$" SearchType="PropertyName" /> 
                </telerik:SerializationMetadataCollection> 
            </telerik:PersistenceManager.SerializationOptions> 
        </telerik:RadButton> 
    

    Example 2: Using Expression to serialize all properties (of RadButton) containing Width in their name - like Width, MinWidth and MaxWidth

        <telerik:RadButton> 
            <telerik:PersistenceManager.SerializationOptions> 
                <telerik:SerializationMetadataCollection> 
                    <telerik:PropertyNameMetadata Condition="Only" Expression="Width" SearchType="PropertyName" /> 
                </telerik:SerializationMetadataCollection> 
            </telerik:PersistenceManager.SerializationOptions> 
        </telerik:RadButton> 
    
  • 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:

Example 3: Serializing only the IsSelected and IsExpanding properties of RadTreeView

<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> 

Example 4: Serializing all RadTreeView properties except the IsSelected

<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> 

See Also

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