Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
NavigationWindow Class

Updated: November 2007

Represents a window that supports content navigation.

Namespace:  System.Windows.Navigation
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/xaml/presentation

Visual Basic (Declaration)
<ContentPropertyAttribute> _
<TemplatePartAttribute(Name := "PART_NavWinCP", Type := GetType(ContentPresenter))> _
Public Class NavigationWindow _
    Inherits Window
Visual Basic (Usage)
Dim instance As NavigationWindow
C#
[ContentPropertyAttribute]
[TemplatePartAttribute(Name = "PART_NavWinCP", Type = typeof(ContentPresenter))]
public class NavigationWindow : Window
Visual C++
[ContentPropertyAttribute]
[TemplatePartAttribute(Name = L"PART_NavWinCP", Type = typeof(ContentPresenter))]
public ref class NavigationWindow : public Window
J#
/** @attribute ContentPropertyAttribute */
/** @attribute TemplatePartAttribute(Name = "PART_NavWinCP", Type = ContentPresenter) */
public class NavigationWindow extends Window
JScript
public class NavigationWindow extends Window
XAML Object Element Usage
<NavigationWindow>
  Content
</NavigationWindow>

NavigationWindow derives from Window and extends it with the ability to navigate to and display content.

Content can be any .NET Framework object or HTML file. In general, however, a Page object is the preferred way to package content for navigation.

Content can be navigated to by setting the Source property with the URI for the desired content. Additionally, content can be navigated to by using one of the following overloads of the Navigate method:

When content is navigated to by URI, NavigationWindow will return an object that contains the content.

Note:

Navigation by URI also supports navigation to a content fragment. See FragmentNavigation.

Alternatively, content can be navigated to by using one of the Navigate method overloads that accepts an object:

The lifetime of a navigation can be tracked through the following events:

Not all events are raised each time that a navigation occurs; the set of events that are raised is determined by the type of navigation that occurs (content or content fragment) and how the navigation completes (canceled, stopped, or failed).

The following figure illustrates the sequence in which these events will fire:

Page navigation flow chart

During or after a navigation, NavigationWindow provides information about the content that is being navigated to, including the URI of the content being navigated to (Source), the URI of the current content (CurrentSource), and an object that contains the content that was navigated to (Content).

When content is navigated to, NavigationWindow records the navigation as an entry in navigation history. An entry is added to back navigation history when either a new navigation occurs, by calling the Navigate method, or by navigating to an entry in forward navigation history, by calling GoForward. An entry is added to forward navigation history by navigating to an entry in back navigation history, by calling GoBack. CanGoBack and CanGoForward report whether there are entries in back and forward navigation history, respectively.

The first time that one piece of content is navigated to from another piece of content, NavigationWindow automatically displays a navigation UI that allows users to navigate back and forwards through navigation history. You can configure when the navigation UI is shown by setting the ShowsNavigationUI property.

The most recent entry in back navigation history can be removed by calling RemoveBackEntry.

NavigationWindow does not store an instance of a content object in navigation history. Instead, NavigationWindow 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 several techniques by which you can store a piece of state for a piece of content in navigation history, which include:

Using AddBackEntry, you can also remember multiple sets of state for a single page instance (see Remember Multiple Sets of State per Page Instance).

NavigationWindow is one of two navigators in WPF, the other being Frame. Essentially, navigator is a class supports navigation and navigation history. Visually, XBAPs use Internet Explorer 7 as a navigator, to provide an integrated user experience. However, XBAPs actually use NavigationWindow as the navigator; the MainWindow property of an XBAP running in Internet Explorer 7 will return a reference to the NavigationWindow, and the navigation history that is managed by the NavigationWindow is integrated with the navigation history that is managed by Internet Explorer 7.

Content Model: NavigationWindow is a ContentControl, which means that NavigationWindow can contain content such as text, images, or panels. Also, NavigationWindow is a root element and, consequently, cannot be part of another element's content. For more information about the content model for Button, see Content Models.

The following example shows how to create a NavigationWindow.

C#
<NavigationWindow 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="MainWindow"
    Title="NavigationWindow Sample"
    Source="http://www.microsoft.com" />

System..::.Object
  System.Windows.Threading..::.DispatcherObject
    System.Windows..::.DependencyObject
      System.Windows.Media..::.Visual
        System.Windows..::.UIElement
          System.Windows..::.FrameworkElement
            System.Windows.Controls..::.Control
              System.Windows.Controls..::.ContentControl
                System.Windows..::.Window
                  System.Windows.Navigation..::.NavigationWindow
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows Vista

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

.NET Framework

Supported in: 3.5, 3.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker