Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigating to same page in windows phone 8

In my WP8 app, i have situation where i have to navigate from one page to another and afterwards i need to reload the same page for some reasons.

MainPage.xaml --> Page1.xaml --> Page1.xaml --> Page1.xaml

When user press the backkey should go back to "MainPage.xaml" page.

I tried using the NavigationService.navigate() for navigation, some reason i couldn't able to reload the page. If i pass any unique query strings (eg: Guid) with navigation url, i am able to reload the page. But, when i press back button - it never goes back to Mainpage.xaml page.

Is there any best way to achieve this?

like image 653
Mahender Avatar asked Feb 17 '23 23:02

Mahender


1 Answers

Pass in a query string every time you reload the page (such as your random GUID). On your OnNavigatedTo method check if the GUID query string exists. If it does exist, you know that you don't want this page on the Navigation Stack because it's the reloaded version, so you can remove it by calling NavigationService.RemoveBackEntry.

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    string guid = string.Empty;
    if (NavigationContext.QueryString.TryGetValue("guid", out guid))
    {
       //guid exists therefore it's a reload, so delete the last entry
       //from the navigation stack
       if(NavigationService.CanGoBack)
          NavigationService.RemoveBackEntry();
    }
}
like image 87
keyboardP Avatar answered Mar 03 '23 11:03

keyboardP