Page::KeepAlive Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets or sets a value that indicates whether the Page instance is retained in navigation history.

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

property bool KeepAlive {
	bool get();
	void set(bool value);

Property Value

Type: System::Boolean

true if the Page instance is retained in navigation history; otherwise, false. The default is false.

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

Identifier field


Metadata properties set to true



The metadata type on this dependency property is PropertyMetadata, not FrameworkPropertyMetadata.

The following example shows how to use XAML to retain an instance of the Page class across multiple navigations.

<Page x:Class="CSharp.HomePage"
No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.0
Return to top