本示例演示如何定位到向前导航历史记录中的项。
示例
从承载于 NavigationWindow、Frame use NavigationService 或 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.");
}
}
CanGoForward 和 GoForward 由 NavigationWindow、Frame 和 NavigationService 实现。
注意 |
|---|
如果您调用 GoForward,而在向前导航历史记录中没有项,则会引发 InvalidOperationException。 |
注意