Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Page.KeepAlive Property

Gets or sets whether an instance of a Page is retained in navigation history. This is a dependency property.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public bool KeepAlive { get; set; }
/** @property */
public boolean get_KeepAlive ()

/** @property */
public void set_KeepAlive (boolean value)

public function get KeepAlive () : boolean

public function set KeepAlive (value : boolean)

<object KeepAlive="bool" .../>

Property Value

A Boolean value that is true to retain an instance of a Page in navigation history; otherwise, false (the default).

Identifier Field

KeepAliveProperty

Metadata Flags

None

When a page is first navigated to, a new instance of the Page class is created. By default, subsequent navigations to the page (using navigation UI or a Hyperlink) cause a new instance of the Page class to be created.

Sometimes, however, a page needs to remember state from one instance to the next. In these cases, WPF offers several techniques for doing so, which are covered in the following topics:

In general, you should only consider setting KeepAlive to true when your requirements for remembering state are more complex than can be easily catered to by the techniques that are discussed in these topics.

NoteNote:

instances of pages that are defined using only code are always retained in navigation history.

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

<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    WindowTitle="HomePage"
    KeepAlive="True"
    >

	...

</Page>

<Page x:Class="CSharp.HomePage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  WindowTitle="HomePage"
    >

	...

</Page>

using System;
using System.Windows;
using System.Windows.Controls;

namespace CSharp
{
    public partial class HomePage : Page
    {
        public HomePage()
        {
            InitializeComponent();

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

    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft