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

Gets the navigation service that the host of the page (Windows Internet Explorer, NavigationWindow, Frame) is using to manage navigation.

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

public NavigationService NavigationService { get; }
/** @property */
public NavigationService get_NavigationService ()

public function get NavigationService () : NavigationService

You cannot use this property in XAML.

Property Value

The NavigationService object that the host of the page (Windows Internet Explorer, NavigationWindow, Frame) is using to manage navigation; a null reference (Nothing in Visual Basic) otherwise.

Pages can be hosted by multiple types of hosts, including Window, NavigationWindow, Frame, and a browser.

Pages often need to integrate with their host's navigation to provide in-page navigation support. However, because a page may not know what its host will be at run time, it can't integrate directly with its host's navigation members to do so.

Instead, it can attempt to use a navigation service, which is a service that supports browser-style navigation and is encapsulated by the NavigationService class. You can't create your own NavigationService instance, though. Instead, host types such as NavigationWindow, Frame, or a browser, create their own NavigationService instance that you can access from the NavigationService property.

The navigation service that is returned from the NavigationService property is the instance of the NavigationService class that is managed by the first navigator up the visual tree. If one isn't found, a null reference (Nothing in Visual Basic) is returned, indicating a page's host does not support navigation.

NoteNote:

The Window class does not support navigation and, consequently, does not provide a navigation service.

The following example shows how a page can check if a navigation service is available and, if so, use it to navigate back to the previous page.

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

        // Don't allow back navigation if no navigation service
        if (this.NavigationService != null)
        {
            this.goBackButton.IsEnabled = false;
        }
    }

    void goBackButton_Click(object sender, RoutedEventArgs e)
    {
        // Go to previous entry in journal back stack
        if (this.NavigationService.CanGoBack)
        {
            this.NavigationService.GoBack();
        }
    }
}

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