How to get info about previous page on Frame.GoBack()

放肆的年华 提交于 2019-12-11 08:55:31

问题


Say we have some Page PageA and I have a button that, when clicked, does the following:

Frame.NavigateTo(typeof(PageB));

After the user is done doing stuff, he navigates back from PageB to PageA calling Frame.GoBack()

I want be able to determine that I'm navigating back from PageB

I could use:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    e.NavigationMode
}

But this only tells me that I'm navigating back, not that I'm navigating back from PageB.

Is this even a good windows-phone-guidelines approach (did not find this particular case in the docs)?


回答1:


I think you should be able to do it by using Frame.ForwardStack property which holds forward navigation history.

A short sample which should work:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    var lastPage = Frame.ForwardStack.LastOrDefault();
    if (lastPage != null && lastPage.SourcePageType.Equals(typeof(desiredPage)))
        { /* do something */ }
}


来源:https://stackoverflow.com/questions/31002778/how-to-get-info-about-previous-page-on-frame-goback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!