Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
NavigationService encapsulates the ability to download content within the context of a browser-style navigation.
Content can be any type of .NET Framework 3.0 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 will fire:
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, which include:
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.
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).
The NavigationService Sample provides demonstrates the most common NavigationService members being used to implement a simple XAML-browser application.
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 EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.