Change page after logging in to Xamarin Forms

I have an xamarin form application that has a login page. Upon successful login, the application will go to MainPageMenu, which is the main 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());
}

On the 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 will go to the fpm page correctly, but the problem is that when I click the menu icon, I get a page with detailed information not the main page.

This problem is similar to that described in this post . And the above code is selected as the answer to the question. But the code does not work for me. There is a similar question in stack overflow , 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 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>
+4
2

:

Application.Current.MainPage = new NavigationPage(new MainPageMenus());

. NavigationPage MasterDetailPage . , MasterDetailPage . .

DETAIL PAGE MasterDetailPage (ContentPages).

, : "MainPageMenus" ( MasterDetailPage) ANOTHER MasterDetailPage.

//Some code for login .....

MasterDetailPage fpm = new MasterDetailPage
{
      Master = new MainPageMenus(),
      Detail = new NavigationPage(new MainPage())
};
Application.Current.MainPage = fpm;

: ContentPage, MainPageMenus, MainPageMenusAsContentPage. Xaml MainPageMenusAsContentPage:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="XProject.Menus.MainPageMenusAsContentPage"
             Title="Menu"
             >
    <ContentPage.Content>
        <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.Content>
</ContentPage>

:

var masterDetailPage = new MasterDetailPage()
{
    Master =new MainPageMenusAsContentPage(), 
    Detail = new NavigationPage(new MainPage())
};

Application.Current.MainPage = masterDetailPage;

EDIT: :

masterDetailPage.Detail.PushAsync( CoolPage()); masterDetailPage.Detail = NavigationPage ( CoolPage());

-, ,

+3

, :

DetailPage . , , MasterDetailPage ContentPage, TabbedPage, NavigationPage ContentPage. .

API-, , . , . MainPage MasterDetailPage, , , .

+1

Source: https://habr.com/ru/post/1693883/


All Articles