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.
Go to Solution Explorer-->Your Project-->Portable-->Right click-->Add-->New Item (Ctrl+Shift+A). Now, select Forms XAML page and give the name (MainPage. xaml). In this step, add another one page, whose name is called SecondPage.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With