你好,在UWP我可以导航到另一个页面,如:
Frame.Navigate(typeof(AnotherPage), someObject);
并在AnotherPage
中,如果我想要检索对象:
protected override void OnNavigationTo(NavigationEventArgs e) {
SomeObject someObject = (SomeObject) e.Parameter;
//here I would like to know from what page I am navigating
}
你能告诉我如何从我浏览的页面中找到答案吗?感谢。
答案 0 :(得分:5)
导航完成后,将上一页放在Frame的BackStack上,只需查询该集合。
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SomeObject someObject = (SomeObject)e.Parameter;
PageStackEntry previousPage = Frame.BackStack.Last();
Type previousPageType = previousPage?.SourcePageType;
base.OnNavigatedTo(e);
}