NavigationService NavigationService NavigationService NavigationService Class

定義

包含支援巡覽的方法、屬性和事件。Contains methods, properties, and events to support navigation.

public ref class NavigationService sealed
public sealed class NavigationService
type NavigationService = class
Public NotInheritable Class NavigationService
繼承
NavigationServiceNavigationServiceNavigationServiceNavigationService

備註

NavigationService封裝在瀏覽器樣式導覽的內容中下載內容的能力。NavigationService encapsulates the ability to download content within the context of a browser-style navigation.

內容可以是任何類型的 .NET Framework 物件和 HTML 檔案。Content can be any type of .NET Framework object and HTML files. 不過,一般情況下,頁面是慣用的封裝內容以供流覽的方式(請Page參閱)。In general, however, pages are the preferred as the way to package content for navigation (see Page).

藉由提供物件的實例並呼叫Navigate接受物件之方法的多載,即可流覽至內容:Content can be navigated to by providing an instance of an object and calling an overload of the Navigate method that accepts an object:

或者,將相對或絕對 URI 傳遞至接受 URI 的其中一個Navigate方法多載,即可流覽至內容:Alternatively, content can be navigated to by passing a relative or absolute URI to one of the Navigate method overloads that accepts a URI:

當以 URI 流覽內容時, NavigationService將會傳回包含內容的物件。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

在導覽期間或之後, NavigationService會提供所流覽之內容的相關資訊,包括所流覽之內容的 uri (Source)、目前內容的 uri (CurrentSource),以及包含流覽至的內容(Content)。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).

流覽內容時, NavigationService會將導覽記錄為導覽歷程記錄中的專案。When content is navigated to, NavigationService records the navigation as an entry in navigation history. 當出現新的導覽、呼叫Navigate方法,或藉由呼叫GoForward來流覽至向前導覽記錄中的專案時,會將專案加入至上一頁導覽記錄。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. 藉由呼叫GoBack,藉由流覽至 [上一頁導覽歷程記錄] 中的專案,將專案新增至 [向前流覽歷程記錄]。An entry is added to forward navigation history by navigating to an entry in back navigation history, by calling GoBack. CanGoBackCanGoForward報告 [上一頁] 和 [下一頁] 導覽歷程記錄中是否分別有專案。CanGoBack and CanGoForward report whether there are entries in back and forward navigation history, respectively. 此外,您可以藉由呼叫RemoveBackEntry來移除後端導覽歷程記錄中的最新專案。Also, the most recent entry in back navigation history can be removed by calling RemoveBackEntry.

根據預設, NavigationService不會將內容物件的實例儲存在導覽歷程記錄中。By default, NavigationService does not store an instance of a content object in navigation history. 相反地NavigationService ,會在每次使用導覽歷程記錄流覽時,建立 content 物件的新實例。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. 不過,WPF 提供數種技術,讓您可以在導覽歷程記錄中儲存一段內容的狀態。However, WPF provides several techniques by which you can store a piece of state for a piece of content in navigation history.

使用AddBackEntry,您也可以記住單一頁面實例的多個狀態集。Using AddBackEntry, you can also remember multiple sets of state for a single page instance.

NavigationService是類別,因此無法具現化, NavigationService而是由導覽器用來啟用導覽。 sealedNavigationService is a sealed class and therefore cannot be instantiated; instead, NavigationService is used by navigators to enable navigation. 在 WPF 中有兩個導覽器NavigationWindowFrame和。In WPF, there are two navigators: NavigationWindow and Frame.

以視覺化的Internet Explorer 7Internet Explorer 7方式使用作為導覽器,以提供整合式使用者體驗。XBAPXBAPsVisually, XBAPXBAPs use Internet Explorer 7Internet Explorer 7 as a navigator, to provide an integrated user experience. XBAPXBAP MainWindow Internet Explorer 7Internet Explorer 7 NavigationWindow實際上,實際會使用NavigationWindow做為導覽,而在中執行的屬性會傳回的參考,以及由XBAPXBAPs會與Internet Explorer 7Internet Explorer 7以下列方式管理的導覽記錄整合: NavigationWindowPhysically, however, XBAPXBAPs actually use NavigationWindow as the navigator; the MainWindow property of an XBAPXBAP running in Internet Explorer 7Internet 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 7Internet Explorer 7 in the following ways:

  • Navigate由呼叫中的、和來導覽至GoForward內容時, XBAPXBAP GoBack也會將相關導覽歷程記錄專案中Internet Explorer 7Internet Explorer 7的和新增至流覽歷程記錄。When content is navigated to by calling Navigate, GoBack, and GoForward from within an XBAPXBAP the relevant navigation history entries are also added to Internet Explorer 7Internet Explorer 7 navigation history.

  • Internet Explorer 7Internet Explorer 7選取導覽UIUI中的專案時, Internet Explorer 7Internet Explorer 7會導致NavigationService流覽回或轉送至與這些專案相關聯的內容。When entries in the Internet Explorer 7Internet Explorer 7 navigation UIUI are selected, Internet Explorer 7Internet Explorer 7 causes NavigationService to navigate back or forwards to the content that is associated with those entries.

注意

Frame可以提供自己的導覽歷程記錄,或使用主控它之導覽的流覽歷程記錄。A Frame can provide its own navigation history, or use the navigation history of the navigator that hosts it. 如果Frame提供自己的導覽歷程記錄,它可以顯示UIUI自己的導覽,以流覽導覽歷程記錄中的專案; 這些專案不會加入至主機導覽器的流覽歷程NavigationWindow記錄(、 Frame UIUIInternet ExplorerInternet Explorer),因此無法從每個的導覽流覽到(請參閱JournalOwnership)。If Frame provides its own navigation history, it can display its own navigation UIUI to navigate through the entries in navigation history; those entries are not added to the navigation history of the host navigator (NavigationWindow, Frame, Internet ExplorerInternet Explorer) and, consequently, cannot be navigated to from the navigation UIUI of each (see JournalOwnership).

屬性

CanGoBack CanGoBack CanGoBack CanGoBack

取得值,這個值表示向後巡覽記錄中是否至少有一個項目。Gets a value that indicates whether there is at least one entry in back navigation history.

CanGoForward CanGoForward CanGoForward CanGoForward

取得值,這個值表示向前巡覽記錄中是否至少有一個項目。Gets a value that indicates whether there is at least one entry in forward navigation history.

Content Content Content Content

取得或設定包含目前內容之物件的參考。Gets or sets a reference to the object that contains the current content.

CurrentSource CurrentSource CurrentSource CurrentSource

取得最後巡覽之內容的 URI。Gets the URI of the content that was last navigated to.

Source Source Source Source

取得或設定目前內容的 URI,或目前正在巡覽之新內容的 URI。Gets or sets the URI of the current content, or the URI of new content that is currently being navigated to.

方法

AddBackEntry(CustomContentState) AddBackEntry(CustomContentState) AddBackEntry(CustomContentState) AddBackEntry(CustomContentState)

將項目加入至包含 CustomContentState 物件的向後巡覽記錄。Adds an entry to back navigation history that contains a CustomContentState object.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetNavigationService(DependencyObject) GetNavigationService(DependencyObject) GetNavigationService(DependencyObject) GetNavigationService(DependencyObject)

取得內容包含所指定 NavigationService 之巡覽器的 DependencyObject 參考。Gets a reference to the NavigationService for the navigator whose content contains the specified DependencyObject.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
GoBack() GoBack() GoBack() GoBack()

巡覽至向後巡覽記錄中的最新項目 (如果有的話)。Navigates to the most recent entry in back navigation history, if there is one.

GoForward() GoForward() GoForward() GoForward()

巡覽至向前巡覽記錄中的最新項目 (如果有的話)。Navigate to the most recent entry in forward navigation history, if there is one.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
Navigate(Object) Navigate(Object) Navigate(Object) Navigate(Object)

非同步巡覽至物件所包含的內容。Navigate asynchronously to content that is contained by an object.

Navigate(Object, Object) Navigate(Object, Object) Navigate(Object, Object) Navigate(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.

Navigate(Uri) Navigate(Uri) Navigate(Uri) Navigate(Uri)

非同步巡覽至 URI 所指定的內容。Navigate asynchronously to content that is specified by a URI.

Navigate(Uri, Object) Navigate(Uri, Object) Navigate(Uri, Object) Navigate(Uri, Object)

非同步巡覽至位在 URI 的來源內容,並傳遞包含要在瀏覽期間用來處理之資料的物件。Navigate asynchronously to source content located at a URI, and pass an object that contains data to be used for processing during navigation.

Navigate(Uri, Object, Boolean) Navigate(Uri, Object, Boolean) Navigate(Uri, Object, Boolean) Navigate(Uri, Object, Boolean)

非同步巡覽至位在 URI 的來源內容、傳遞包含瀏覽狀態的物件以在瀏覽期間用於處理,以及對內容進行沙箱測試。Navigate asynchronously to source content located at a URI, pass an object containing navigation state for processing during navigation, and sandbox the content.

Refresh() Refresh() Refresh() Refresh()

重新載入目前的內容。Reloads the current content.

RemoveBackEntry() RemoveBackEntry() RemoveBackEntry() RemoveBackEntry()

將最新的日誌項目從向後記錄中移除。Removes the most recent journal entry from back history.

StopLoading() StopLoading() StopLoading() StopLoading()

停止為目前的巡覽要求進一步下載內容。Stops further downloading of content for the current navigation request.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

事件

FragmentNavigation FragmentNavigation FragmentNavigation FragmentNavigation

在開始巡覽內容片段時發生,如果需要的片段位在目前的內容中,則會立即發生,如果需要的片段位在不同的內容中,則會在載入來源 XAMLXAML 內容之後發生。Occurs when navigation to a content fragment begins, which occurs immediately, if the desired fragment is in the current content, or after the source XAMLXAML content has been loaded, if the desired fragment is in different content.

LoadCompleted LoadCompleted LoadCompleted LoadCompleted

當所巡覽的內容被載入、剖析以及開始呈現時,就會發生。Occurs when content that was navigated to has been loaded, parsed, and has begun rendering.

Navigated Navigated Navigated Navigated

當找到所要巡覽的內容,此內容也可以從 Content 屬性取得 (雖然可能尚未完全載入) 時,就會發生。Occurs 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.

Navigating Navigating Navigating Navigating

要求新的巡覽時發生。Occurs when a new navigation is requested.

NavigationFailed NavigationFailed NavigationFailed NavigationFailed

在巡覽所要求的內容時,如果發生錯誤,就會發生。Occurs when an error occurs while navigating to the requested content.

NavigationProgress NavigationProgress NavigationProgress NavigationProgress

在下載期間定期發生以提供導覽進度資訊。Occurs periodically during a download to provide navigation progress information.

NavigationStopped NavigationStopped NavigationStopped NavigationStopped

當呼叫 StopLoading() 方法,或是當目前的巡覽正在進行,但又要求新的巡覽時,就會發生。Occurs when the StopLoading() method is called, or when a new navigation is requested while a current navigation is in progress.

適用於