Compartir a través de


Cómo: Navegar hacia atrás por el historial de navegación

En este ejemplo se muestra cómo navegar hacia atrás en las entradas del historial de navegación.

Ejemplo

Puede navegar hacia atrás mediante el historial de navegación (de entrada en entrada) por el código que se está ejecutando desde el contenido que se hospeda en NavigationWindow, Frame, NavigationService o Windows Internet Explorer.

Para navegar hacia atrás a la entrada anterior es preciso comprobar primero que haya entradas anteriores en el historial de navegación inspeccionando la propiedad CanGoBack, antes de navegar a la entrada anterior llamando al método GoBack. Esto se muestra en el siguiente ejemplo:

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

CanGoBack y GoBack se implementan mediante NavigationWindow, Frame y NavigationService.

NotaNota

Si llama a GoBack y no hay ninguna entrada hacia atrás en el historial de navegación, se inicia una excepción InvalidOperationException.