共用方式為


HOW TO:在巡覽記錄中前移

本範例說明如何巡覽至向前巡覽記錄中的項目。

範例

從裝載在 NavigationWindow 之內容執行的程式碼、使用 NavigationServiceFrame 或 Windows Internet Explorer 可以在巡覽記錄中向前巡覽,一次一個項目。

向前巡覽一個項目時,必須先檢查向前巡覽記錄中是否有項目,方法是在向前巡覽一個項目之前呼叫 GoForward 方法,以查看 CanGoForward 屬性。 下列範例說明了這個程序:

        Private Sub navigateForwardButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
            ' Navigate forward one page from this page, if there is an entry
            ' in forward navigation history
            If Me.NavigationService.CanGoForward Then
                Me.NavigationService.GoForward()
            Else
                MessageBox.Show("No entries in forward navigation history.")
            End If
        End Sub
void navigateForwardButton_Click(object sender, RoutedEventArgs e)
{
    // Navigate forward one page from this page, if there is an entry
    // in forward navigation history
    if (this.NavigationService.CanGoForward)
    {
        this.NavigationService.GoForward();
    }
    else
    {
        MessageBox.Show("No entries in forward navigation history.");
    }
}

CanGoForwardGoForward 是由 NavigationWindowFrameNavigationService 實作。

注意事項注意事項

如果您呼叫 GoForward,但向前巡覽記錄中沒有任何項目,則會引發 InvalidOperationException