如何:在导航历史记录中向后定位

更新:2007 年 11 月

此示例演示如何在导航历史记录中向后导航到项。

示例

NavigationWindowFrameNavigationService(或 Windows Internet Explorer)中承载的内容运行的代码可以在导航历史记录中一次向后导航一项。

若要向后导航一项,需要在调用 GoBack 方法向后导航一项之前,先通过检查 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.");
    }
}

CanGoBackGoBackNavigationWindowFrameNavigationService 实现。

说明:

如果您调用 GoBack,并且在向后的导航历史记录中没有项,则会引发 InvalidOperationException