I have xamarin form application that has login page. When user login successfully, the application navigate to MainPageMenu
which is a master detail page. I have the same problem. This is my code in app.cs:
public App ()
{
InitializeComponent();
if (ApplicationSettings.NotLogin()) // Method to check if use if logged in or not
MainPage = new LoginPage();
else
MainPage = new NavigationPage(new MainPageMenus());
}
In login Page, I write this code:
//Some code for login .....
MasterDetailPage fpm = new MasterDetailPage
{
Master = new MainPageMenus(),
Detail = new NavigationPage(new MainPage())
};
Application.Current.MainPage = fpm;
The application navigate to fpm page correctly, but the problem is that when I press menu icon, I get the detail page not the master page.
This problem is similar to one described in this post. And the code above is the selected as the answer to the question. But code doesn't work for me. In stack Overflow, there is a similar question and the answer was to use this:
Application.Current.MainPage = new NavigationPage(new MainPageMenus());
But in this case the menu icon is hidden.
Here is the Xml of MainPageMenus:
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XProject.Menus.MainPageMenus"
xmlns:local="clr-namespace:XProject"
Title="E-Clinic"
>
<MasterDetailPage.Master>
<ContentPage Title="Menu">
<StackLayout Orientation="Vertical">
<Button Clicked="GoToApplicationSettingsPage" Text="Application Settings"></Button>
<Button Clicked="GoToHxSettingsPage" Text="Medical History Settings"></Button>
<Button Clicked="GoToVisitsSettingsPage" Text="Visits Settings"></Button>
<Button Clicked="GoToCustomFieldsPage" Text="Custom Fields"></Button>
<Button Clicked="GoToAddCustomFieldsPage" Text="Add Custom Fields"></Button>
<Button Clicked="GoToAddCommonInfoPage" Text="Common Info"></Button>
<Button Clicked="GoToAddStatisticsPage" Text="Statistics"></Button>
<Button Clicked="GoToBackupPage" Text="Create Backup"></Button>
<Button Clicked="GoToRestoreBackupPage" Text="Restore Backup"></Button>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<local:MainPage></local:MainPage>
</MasterDetailPage.Detail>
</MasterDetailPage>