Allowed Types
When loading the persisted layout, the PersistenceFramework will instantiate the saved types only if they are allowed. Otherwise, a NotSupportedException
is thrown.
To allow specific types, add them in the AllowedTypes
collection of the PersistenceManager
class.
When the PersistenceManager
gets initialized the AllowedTypes
collection is automatically filled with several WPF native types and also types from the Telerik.Windows.Controls
assembly.
Allowing a type using the AllowedTypes collection of the PersistenceManager
PersistenceManager manager = new PersistenceManager();
manager.AllowedTypes.Add(typeof(SolidColorBrush));
Dim manager As PersistenceManager = New PersistenceManager()
manager.AllowedTypes.Add(GetType(SolidColorBrush))
Allowing a type using the AllowTypes extension method
PersistenceManager manager = new PersistenceManager().AllowTypes(typeof(SolidColorBrush));
Dim manager As PersistenceManager = New PersistenceManager().AllowTypes(GetType(SolidColorBrush))
Allowing Types from the Telerik Assemblies
Each Telerik assembly has an extension method part of the associated AllowedTypesExtensions
class that allows you to automatically load the Telerik types in the AllowedTypes
collection of the PersistenceManager
.
The following example shows how to allow the types that are defined in the Telerik.Windows.Controls.Docking
and Telerik.Windows.Controls.Navigation
assemblies.
Allowing the types that are used in the Telerik.Windows.Controls.Docking and Telerik.Windows.Controls.Navigation assemblies
PersistenceManager manager = new PersistenceManager()
.AllowDockingControls()
.AllowNavigationControls();
Dim manager As PersistenceManager = New PersistenceManager()
.AllowDockingControls()
.AllowNavigationControls()
Allowing Internal Types
In cases where internal WPF types need to be added to the AllowedTypes collection, you can obtain them at runtime and utilize the AllowTypes method. One such case is with the native WPF Selector
class that assigns the SelectedItems
property to a SelectedItemCollection
type, which is internal. In this specific scenario, invoking the AllowInputControls
method will resolve this, however, if you need to allow internal types, you can follow the approach from the following example:
Allowing internal types via the AllowTypes method
var listBox = new ListBox();
manager.AllowTypes(listBox.SelectedItems.GetType());
Dim listBox = New ListBox()
manager.AllowTypes(listBox.SelectedItems.GetType)
TypeRestored Event
To retrieve each type that is present in the saved layout, you can utilize the TypeRestored
event. You can inspect both the type and its assembly, and decide whether to allow the PersistenceFramework to instantiate it, by adding it to the AllowedTypes collection. The event arguments are of the type of TypeRestoredEventArgs
and provide the following API:
-
Type
—Provides the type that is restored. -
AssemblyQualifiedName
—Provides the type's assembly name.
Utilizing the TypeRestored event
private void Manager_TypeRestored(object sender, Persistence.Events.TypeRestoredEventArgs e)
{
var type = e.Type; // Review the type and decide whether to allow the PersistenceFramework to instantiate it by adding it to the AllowedTypes collection.
}
Private Sub Manager_TypeRestored(sender As Object, e As Persistence.Events.TypeRestoredEventArgs)
Dim type = e.Type ' Review the type and decide whether to allow the PersistenceFramework to instantiate it by adding it to the AllowedTypes collection.
End Sub
Allowing Types when Using IsolatedStorageProvider
To allow types to be instantiated by the PersistenceFramework when working with the IsolatedStorageProvider
, you need to pass a new PersistenceManager
instance to its constructor. On it, you can utilize the AllowTypes extension method or use its AllowedTypes collection.
Allowing types when using IsolatedStorageProvider
PersistenceManager manager = new PersistenceManager()
.AllowDockingControls()
.AllowNavigationControls();
manager.AllowedTypes.Add(typeof(MyCustomType));
IsolatedStorageProvider isoProvider = new IsolatedStorageProvider(manager);
Dim manager As PersistenceManager = New PersistenceManager()
.AllowDockingControls()
.AllowNavigationControls()
manager.AllowedTypes.Add(GetType(MyCustomType))
Dim isoProvider As IsolatedStorageProvider = New IsolatedStorageProvider(manager)