Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinRT - How to ignore or delete page from navigation history

I have following situation in my WinRT metro (c# - xaml) application :

User launch the application and he or she is not logged in. In the menu bar I have button which navigates them to Shopping cart. It's important to mention that they can click on it regardless of logged in/out status.

So I have this :

Home Page - > Login Page - > Shopping Cart

And everything works great, but when I try press BACK button on my Shopping Cart page I'm navigated back to Login Page, which make sense, because page is in my navigation history. But I don't want that, I want to return user to Home Page and skip login page.

My question is how to do that, and how to manipulate Frame Navigation Stack on WinRT. I tried with going Back twice, but with no luck.

Btw, my page is "LayoutAwarePage" page and I'm using NavigationService similar to this http://dotnetbyexample.blogspot.com/2012/06/navigationservice-for-winrt.html.

like image 283
rjovic Avatar asked Oct 03 '12 16:10

rjovic


3 Answers

You can approach it in different ways. You can make it so the back button navigates back multiple times until it reaches the home page or skips through the log in page. You could also make the log in page something that shows up outside of the navigation Frame - either on a popup or in a different layer in the application.

*Update

In 8.1 the platform introduced the BackStack and ForwardStack properties on the Frame which you can manipulate.

like image 191
Filip Skakun Avatar answered Nov 05 '22 14:11

Filip Skakun


I know it's old, but since Google found this page for me, maybe someone else will find this page too.

The answer, while a valid work-around, does not answer the question.

You can use this on the login page, removing it from the back stack.

if(login_was_successful == true)
{
    this.Frame.Navigate(typeof(ShoppingCard));

    if(this.Frame.CanGoBack)
    {
        this.Frame.BackStack.RemoveAt(0);
    }
}
like image 42
Drew Avatar answered Nov 05 '22 13:11

Drew


There is a LayoutAwarePage.cs file in the Common folder of your project. You can change the back button behaviour from this file.

 protected virtual void GoBack(object sender, RoutedEventArgs e)
        {

            while (this.Frame.CanGoBack) this.Frame.GoBack();

            // Use the navigation frame to return to the previous page
            //if (this.Frame != null && this.Frame.CanGoBack) this.Frame.GoBack();
        } 
like image 32
user1106633 Avatar answered Nov 05 '22 15:11

user1106633