5
votes

I'm creating an app using Xamarin Forms where when a user launches an app for the first time, they are sent to a login page. Once they log in, they're redirected to the MasterPage, which is a MasterDetail Page. However, when I try to navigate to the new MasterDetail Page, I only get the Detail Page, and the button to show the Master Portion is missing. The only thing appearing on the app bar is the title I set. I'm currently going to the MasterPage like this:

App.Current.MainPage = new NavigationPage(new MasterPage())
{
     Title = "Welcome " + user.firstName
};

Every other run, this isn't an issue, since when a user opens the app it automatically logs them in and goes right to the MasterPage, except during their first use. However, this is a very important issue for me since it happens the first time a user uses my app and it will be part of their first impression.

1

1 Answers

9
votes

When you use a MasterDetailpage, you should not wrap it into a Navigationpage (like your code-example). Because the MasterDetailPage should everytime be on top and not inside a NavigationPage.

To navigate between different pages you should wrap your DetailPage from the MasterDetailPage inside a NavigationPage.

Here some code for clarification:

var view = new MyFirstPage();
Application.Current.MainPage = new MasterPage(view);

And inside the MasterPage constructor, do the following:

public MasterPage(Page detailpage)
{
    // Set the master-part
    Master = new MasterContentPage();

    // Set detail-part (with a navigation page)
    Detail = new NavigationPage(detailpage);
}

And after that, you can navigate inside your app with this navigation:

var mdp = Application.Current.MainPage as MasterDetailPage;
await mdp.Detail.Navigation.PushAsync(myNextPage);

I usually create a static helper class AppNavigator to do this stuff.

For further information, look at the MasterDetailPage instructions on the Xamarin developer guides.