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.

NavigationService Class

Contains methods, properties, and events to support navigation.

System.Object
  System.Windows.Navigation.NavigationService

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

public sealed class NavigationService

The NavigationService type exposes the following members.

  NameDescription
Public propertyCanGoBackGets a value that indicates whether there is at least one entry in back navigation history.
Public propertyCanGoForwardGets a value that indicates whether there is at least one entry in forward navigation history.
Public propertyContentGets or sets a reference to the object that contains the current content.
Public propertyCurrentSourceGets the uniform resource identifier (URI) of the content that was last navigated to.
Public propertySourceGets or sets the uniform resource identifier (URI) of the current content, or the URI of new content that is currently being navigated to.
Top

  NameDescription
Public methodAddBackEntryAdds an entry to back navigation history that contains a CustomContentState object.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodStatic memberGetNavigationServiceGets a reference to the NavigationService for the navigator whose content contains the specified DependencyObject.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGoBackNavigates to the most recent entry in back navigation history, if there is one.
Public methodGoForwardNavigate to the most recent entry in forward navigation history, if there is one.
Public methodNavigate(Object)Navigate asynchronously to content that is contained by an object.
Public methodNavigate(Uri)Navigate asynchronously to content that is specified by a uniform resource identifier (URI).
Public methodNavigate(Object, Object)Navigate asynchronously to content that is contained by an object, and pass an object that contains data to be used for processing during navigation.
Public methodNavigate(Uri, Object)Navigate asynchronously to source content located at a uniform resource identifier (URI), and pass an object that contains data to be used for processing during navigation.
Public methodNavigate(Uri, Object, Boolean)Navigate asynchronously to source content located at a uniform resource identifier (URI), pass an object containing navigation state for processing during navigation, and sandbox the content.
Public methodRefreshReloads the current content.
Public methodRemoveBackEntryRemoves the most recent journal entry from back history.
Public methodStopLoadingStops further downloading of content for the current navigation request.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventFragmentNavigationOccurs when navigation to a content fragment begins, which occurs immediately, if the desired fragment is in the current content, or after the source XAML content has been loaded, if the desired fragment is in different content.
Public eventLoadCompletedOccurs when content that was navigated to has been loaded, parsed, and has begun rendering.
Public eventNavigatedOccurs when the content that is being navigated to has been found, and is available from the Content property, although it may not have completed loading.
Public eventNavigatingOccurs when a new navigation is requested.
Public eventNavigationFailedOccurs when an error occurs while navigating to the requested content.
Public eventNavigationProgressOccurs periodically during a download to provide navigation progress information.
Public eventNavigationStoppedOccurs when the StopLoading method is called, or when a new navigation is requested while a current navigation is in progress.
Top

NavigationService encapsulates the ability to download content within the context of a browser-style navigation.

Content can be any type of .NET Framework object and HTML files. In general, however, pages are the preferred as the way to package content for navigation (see Page).

Content can be navigated to by providing an instance of an object and calling an overload of the Navigate method that accepts an object:

Alternatively, content can be navigated to by passing a relative or absolute uniform resource identifier (URI) to one of the Navigate method overloads that accepts a URI:

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

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 are raised:

Page navigation flow chart

During or after a navigation, NavigationService 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, NavigationService 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. Also, the most recent entry in back navigation history can be removed by calling RemoveBackEntry.

By default, NavigationService does not store an instance of a content object in navigation history. Instead, NavigationService 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.

Using AddBackEntry, you can also remember multiple sets of state for a single page instance.

NavigationService is sealed class and, therefore, cannot be instantiated; instead, NavigationService is used by navigators to enable navigation. In WPF, there are two navigators: NavigationWindow, Frame.

Visually, XBAPs use Internet Explorer 7 as a navigator, to provide an integrated user experience. Physically, 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 in the following ways:

  • When content is navigated to by calling Navigate, GoBack, and GoForward from within an XBAP the relevant navigation history entries are also added to Internet Explorer 7 navigation history.

  • When entries in the Internet Explorer 7 navigation UI are selected, Internet Explorer 7 causes NavigationService to navigate back or forwards to the content that is associated with those entries.

NoteNote

A Frame can provide its own navigation history, or use the navigation history of the navigator that hosts it. If Frame provides its own navigation history, it can display its own navigation UI to navigate through the entries in navigation history; those entries are not added to the navigation history of the host navigator (NavigationWindow, Frame, Internet Explorer) and, consequently, cannot be navigated to from the navigation UI of each (see JournalOwnership).

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft