Can I find out which page a user came from on Back Button press on WP7?

前端 未结 5 1045
南旧
南旧 2021-01-05 21:14

I haven\'t had much luck finding the answer through google searches, but is it possible to tell which page a user came from?

Or, send a query string on back button

5条回答
  •  猫巷女王i
    2021-01-05 21:54

    You can use the NavigationService.BackStack property and check the first entry in the back stack in the page as it is navigated to.

    If this check needs to be done in several pages, it could be put into a base class. Also, if your situation fits the eula/login scenario mentioned by @Skomski, his answer makes the most sense.

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
    
        var lastPage = NavigationService.BackStack.FirstOrDefault();
    
        if (lastPage != null && lastPage.Source.ToString() == "/MainPage.xaml")
        {
            NavigationService.RemoveBackEntry();
        }
    }
    

提交回复
热议问题