Partilhar via


Como: Navigate Forward Through Navigation History

This example illustrates how to navigate to entries in forward navigation history.

Exemplo

Code that is running from content that is hosted in a NavigationWindow, Frame use NavigationService, or Windows Internet Explorer can navigate forward through navigation history, one entry at a time.

Navigating forward one entry requires first checking that there are entries in forward navigation history, by inspecting the CanGoForward property, before navigating forward one entry, by calling the GoForward method. This is illustrated in the following example:

        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.");
    }
}

CanGoForward and GoForward are implemented by NavigationWindow, Frame, and NavigationService.

Observação

If you call GoForward, and there are no entries in forward navigation history, an InvalidOperationException is raised.