方法: ナビゲーション履歴を前後に移動する
この例では、ナビゲーション履歴のエントリに進むか戻る方法を示します。
例
次のホストのコンテンツから実行されるコードは、一度に 1 つのエントリで、ナビゲーション履歴を前後に移動できます。
NavigationService を使用する Frame
Internet Explorer
1 つのエントリを前方に移動する前に、最初に CanGoForward プロパティ
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.");
}
}
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
1 つのエントリに戻る前に、CanGoBack プロパティ
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.");
}
}
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
CanGoForward、GoForward、CanGoBack、および GoBack は、NavigationWindow、Frame、および NavigationServiceによって実装されます。
手記
GoForward を呼び出して、ナビゲーション履歴の前方にエントリがない場合、または GoBack を呼び出して、ナビゲーション履歴の後方にエントリがない場合は、InvalidOperationException がスローされます。
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET Desktop feedback