Page.KeepAlive Property


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

 property bool KeepAlive { bool get(); void set(bool value); };
public bool KeepAlive { get; set; }
member this.KeepAlive : bool with get, set
Public Property KeepAlive As Boolean

Property Value


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


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

<Page x:Class="CSharp.HomePage"
using System;
using System.Windows;
using System.Windows.Controls;

namespace CSharp
    public partial class HomePage : Page
        public HomePage()

            // Keep this page in navigation history
            this.KeepAlive = true;

Imports System.Windows
Imports System.Windows.Controls

Namespace VisualBasic
    Partial Public Class HomePage
        Inherits Page
        Public Sub New()

            ' Keep this page in navigation history
            Me.KeepAlive = True
        End Sub

    End Class
End Namespace


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

Dependency Property Information

Identifier field KeepAliveProperty
Metadata properties set to true None


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

Applies to

See also