如何获取有关 Frame.GoBack() 上一页的信息 [英] How to get info about previous page on Frame.GoBack()
问题描述
假设我们有一些 Page
PageA 和我有一个按钮,当点击它时,会执行以下操作:
Say we have some Page
PageA and I have a button that, when clicked, does the following:
Frame.NavigateTo(typeof(PageB));
用户完成某件事后,他从 PageB 导航回到 PageA 调用 Frame.GoBack()
After the user is done doing stuff, he navigates back from PageB to PageA calling Frame.GoBack()
我希望能够确定我是从 PageB 返回
I want be able to determine that I'm navigating back from PageB
我可以使用:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
e.NavigationMode
}
但这只能告诉我我正在返回,而不是从 PageB 返回.
But this only tells me that I'm navigating back, not that I'm navigating back from PageB.
这是否是一个很好的 windows-phone-guidelines 方法(在文档中没有找到这种特殊情况)?
Is this even a good windows-phone-guidelines approach (did not find this particular case in the docs)?
推荐答案
我认为您应该可以使用 Frame.ForwardStack 保存向前导航历史记录的属性.
I think you should be able to do it by using Frame.ForwardStack property which holds forward navigation history.
应该有效的简短示例:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var lastPage = Frame.ForwardStack.LastOrDefault();
if (lastPage != null && lastPage.SourcePageType.Equals(typeof(desiredPage)))
{ /* do something */ }
}
这篇关于如何获取有关 Frame.GoBack() 上一页的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!