Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigate to a new page without putting current page on back stack?

In an Windows Phone 7 application I got a CurrentPage, which, on a special event does navigate to a new page using the NavigationService:

NavigationService.Navigate(new Uri("/NewPage.xaml", UriKind.Relative));

Now when the user clicks back on the NewPage I want the app to skip the CurrentPage and go directly to the MainPage of the app.

I tried to use NavigationService.RemoveBackEntry, but this removes the MainPage instead of the CurrentPage.

How do I navigate to a new page without putting the current on the back stack?

like image 603
Sam Avatar asked Jun 11 '12 13:06

Sam


People also ask

How do you move from one screen to another in Flutter without the way back?

But you can set "automaticallyLeadingImplied: false" in the AppBar of the Scaffold you are navigating to.


1 Answers

When navigating to the NewPage.xaml pass along a parameter so you know when to remove the previous page from the backstack.

You can do this as such:

When navigating from CurrentPage.xaml to NewPage.xaml pass along parameter


    bool remove = true;
    String removeParam = remove ? bool.TrueString : bool.FalseString;

    NavigationService.Navigate(new Uri("/NewPage.xaml?removePrevious="+removeParam , UriKind.Relative));

In the OnNavigatedTo event of NewPage.xaml, check whether to remove the previous page or not.


    bool remove = false;

    if (NavigationContext.QueryString.ContainsKey("removePrevious"))
    {
        remove = ((string)NavigationContext.QueryString["removePrevious"]).Equals(bool.TrueString);
        NavigationContext.QueryString.Remove("removePrevious");
    }

    if(remove)
    {
        NavigationService.RemoveBackEntry();
    }

This way, you can decide on the CurrentPage.xaml if you want to remove it from the backstack.

like image 70
akalucas Avatar answered Oct 11 '22 14:10

akalucas