CustomContentState Class

CustomContentState enables the ability to navigate through different states of a single piece of source content without reloading the source content for each subsequent navigation.

System::Object
  System.Windows.Navigation::CustomContentState

Namespace:  System.Windows.Navigation
Assembly:  PresentationFramework (in PresentationFramework.dll)

[SerializableAttribute]
public ref class CustomContentState abstract

The CustomContentState type exposes the following members.

  NameDescription
Protected methodCustomContentStateInitializes a new instance of the CustomContentState class.
Top

  NameDescription
Public propertyJournalEntryNameThe name for the content that is stored in navigation history. The value of JournalEntryName is displayed from NavigationWindow, Frame, and Windows Internet Explorer 7 navigation UI.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodReplayCalled to reapply state to a piece of content when navigation occurs.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

By default, NavigationService does not store an instance of a content object in navigation history. Instead, NavigationService creates a new instance of the content object each time it is navigated to by using navigation history. This behavior is designed to avoid excessive memory consumption when large numbers and large pieces of content are being navigated to. Consequently, the state of the content is not remembered from one navigation to the next. However, WPF provides the ability to associate a piece of custom state with the navigation history entry for a piece of content.

Custom state that is associated with a navigation history entry must be a class that derives from CustomContentState. You associate a CustomContentState object with a navigation history entry by using one of the following techniques:

NoteNote

If you call the AddBackEntry method, you must handle the Navigating event or implement IProvideCustomContentState.

When the navigation history entry is navigated to, WPF checks to see if a custom CustomContentState object is associated with it. If so, it calls Replay to allow the custom CustomContentState object to apply the state it remembered from the previous navigation.

A custom CustomContentState class can override JournalEntryName to change the name that appears for the navigation history entry to which the CustomContentState object is associated. The value that JournalEntryName returns is visible from the navigation UI of the various navigators (Internet Explorer 7, NavigationWindow, Frame).

A class that derives from CustomContentState must be serializable, which means it must at least be augmented with SerializableAttribute, and optionally implement ISerializable.

Important noteImportant

When you store information in custom content state, you cannot store any references to the instance of the page for which you are remembering state if don’t want the content to be retained in memory. This prevents WPF from releasing the page instance, and defeats the purpose of the default navigation history behavior. If you must do this, consider using KeepAlive instead.

The following is an example of a CustomContentState implementation that overrides JournalEntryName.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft