Gets or sets a value that indicates whether the Page instance is retained in navigation history.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
When a page is first navigated to, a new instance of the Page class is created. When a page is navigated away from (either back or forward), an entry for the page is added to navigation history. By default, the entry does not reference the page object. Instead, the entry contains a pack uniform resource identifier (URI) for the page. When the entry for the page is navigated to using navigation history, the pack uniform resource identifier (URI) is used to create a new instance of the page. This behavior is the default, to avoid excessive memory use: retaining page instances can quickly consume memory, particularly those with a nontrivial amount of content. This problem is augmented by the fact that there is no limit to the number of entries that can be stored in the back and forward stacks of navigation history. In contrast, storing pack uniform resource identifiers (URIs) for pages has virtually no impact on memory consumption.
The main side effect of creating new instances of a page is that page state is not remembered from one instance of a page to another. In these cases, Windows Presentation Foundation (WPF) offers several techniques for remembering state.
To keep a page alive, you set the property to true (the default is false).
Pages that are instantiated and navigated to using only code (for example, calling Navigate), are automatically kept alive.
You should avoid setting to true unless you need to:
When a page has a lot of content, it may take a long time to instantiate. If the page is not kept alive, and the page is frequently navigated to, the cost of constantly instantiating the page may have a negative impact on the user experience. However, from a performance perspective, you should rely on the default settings and profile your application's performance; if testing identifies pages with load times that fall below the range required for your application, configuring the pages to be kept alive may be one way to solve the problem.
Entries for pages that are kept alive are not retained in navigation history of an XAML browser application (XBAP) if a user navigates away from and back to the XAML browser application (XBAP). Only journal entries for pages that are not kept alive are retained in navigation history.
The following example shows how to use XAML to retain an instance of the Page class across multiple navigations.
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.