Ilya Mashin
Ilya Mashin

Reputation: 954

Creating a new stack of pages after authorization

I need to create new stack of pages after authentication. In most applications, the authorization form is only a launcher to the application. If i use Navigation.PushAsync(Page), i can return to authorization form if i push back button. I don't need this. MasterDetail Page is created and back button should close app. How to make this functional?

public async void OnAuthorization(object sender, EventArgs a)
    {
        await Navigation.PushAsync(new ProfilePage());
    }

Upvotes: 0

Views: 36

Answers (1)

SushiHangover
SushiHangover

Reputation: 74209

Assuming that the "Authentication Page" is not wrapped in a NavigationPage and the ProfilePage is your MasterDetailPage, you can just replace the MainPage with your ProfilePage.

public async void OnAuthorization(object sender, EventArgs a)
{
    Application.Current.MainPage = new ProfilePage();
}

If you are wrapping it all in a NavigationPage (not sure why you would be as that should only be within the MasterDetailPage.Detail), you could insert your MasterDetailPage into the stack (before the current page) and then pop the current one off the stack. But based upon what your question is implying about zero stack (back button to exit), you would pop to root:

Navigation.InsertPageBefore(new SomeMasterDetailPage(), this);
await Navigation.PopToRootAsync();

Upvotes: 1

Related Questions