Condividi tramite


NavigationService.GoBack Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Navigates to the most recent entry in the back navigation history, or throws an exception if no entry exists in back navigation.

Namespace:  System.Windows.Navigation
Assembly:  System.Windows.Controls.Navigation (in System.Windows.Controls.Navigation.dll)

Syntax

'Declaration
Public Sub GoBack
public void GoBack()

Exceptions

Exception Condition
InvalidOperationException

There are no entries in the back navigation history.

Remarks

Before calling the GoBack method, check the value of the CanGoBack property to determine if an entry exists in the back navigation history.

Examples

The following example shows buttons within a Silverlight page that allow forward and back navigation. The page uses the NavigationService property of the Page class to access the navigation service used by the hosting frame.

Private Sub BackNavButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    If (NavigationService.CanGoBack) Then
        NavigationService.GoBack()
    End If
End Sub

Private Sub ForwardNavButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    If (NavigationService.CanGoForward) Then
        NavigationService.GoForward()
    End If
End Sub
private void BackNavButton_Click(object sender, RoutedEventArgs e)
{
    if (NavigationService.CanGoBack)
    {
        NavigationService.GoBack();
    }
}

private void ForwardNavButton_Click(object sender, RoutedEventArgs e)
{
    if (NavigationService.CanGoForward)
    {
        NavigationService.GoForward();
    }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.