Showing white blank page before navigating from Login page to MasterDetailpage in Xamarin Form

ThiyraashThiyraash Member ✭✭
edited December 2018 in Xamarin.Forms

Hi, I'm working on app in Xamarin form where I need to login first in login page , then if succeed will it navigate to master detail page. I able to achieved it but when navigating from Login page to masterdetail page, it show <1second white blank page in between the navigation. Is that any way to make it navigate more faster without showing the white page? I'm using the masterdetail (https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/master-detail-page) page template provide by the Xamarin form.
Below show how I navigate between the pages.

      MainPage = new LoginPage();
      Application.Current.MainPage = new MasterDetailPage();

Best Answer

  • ThiyraashThiyraash ✭✭
    edited December 2018 Accepted Answer

    Bro @JuniorJiang Thanks a lot for your assist! I able to fix my problem. I follow the idea you said with small changes.

    1. In App.cs
      MainPage = new MainPage(); <=MasterDetailpage

    2. In Masterdetailpage contructor

            public MainPage()
                {
                      InitializeComponent();
                        MasterBehavior = MasterBehavior.Popover;
                       MenuPages.Add((int)MenuItemType.Home, (NavigationPage)Detail);
              //I added this login page as PushModalAsync
                     Navigation.PushModalAsync(new LoginPage());
                 }
      
    3. In LoginPage SignIn button

        private void Login_buton(object sender, EventArgs e)
              {
                  Navigation.PopModalAsync();
      
              }
      

Answers

  • JuniorJiangJuniorJiang Member, Xamarin Team Xamurai

    Hi @Thiyraash , you can try this way to navigate page:

    //Now in LoginPage, want to push to MasterDetailPage
    Navigation.PushAsync(new MasterDetailPage());
    
  • ThiyraashThiyraash Member ✭✭
    Bro @JuniorJiang but according to the Xamarin official web, they mention that masterdetail should be root page.
  • JuniorJiangJuniorJiang Member, Xamarin Team Xamurai

    Yes @Thiyraash , MasterDetailPage is a root page.However this navigate can be designed by your logic.When launch application , first go to MasterDetailPage , then logic find no login , so change page to LoginPage( Push to LoginPage).When login successfully, pop to MasterDetailPage(LoginPage pop).

    First in MasterDetailPage:

    Navigation.PushAsync(new LoginPage ());

    Then back to MasterDetailPage:

    Navigation.PopAsync();
    
  • ThiyraashThiyraash Member ✭✭
    edited December 2018 Accepted Answer

    Bro @JuniorJiang Thanks a lot for your assist! I able to fix my problem. I follow the idea you said with small changes.

    1. In App.cs
      MainPage = new MainPage(); <=MasterDetailpage

    2. In Masterdetailpage contructor

            public MainPage()
                {
                      InitializeComponent();
                        MasterBehavior = MasterBehavior.Popover;
                       MenuPages.Add((int)MenuItemType.Home, (NavigationPage)Detail);
              //I added this login page as PushModalAsync
                     Navigation.PushModalAsync(new LoginPage());
                 }
      
    3. In LoginPage SignIn button

        private void Login_buton(object sender, EventArgs e)
              {
                  Navigation.PopModalAsync();
      
              }
      
  • ClaudyDetryClaudyDetry USMember ✭✭

    Hello,

    I am happy that you have solved your problem.
    I am trying to use the MasterDetail template for my project also.

    Would you know how we can change the default page loaded when the app is launched?
    I tried your solution but in this case, we lose the access to the menu.

  • ThiyraashThiyraash Member ✭✭
    Default page loaded means? Are you referring to the first page (Home page) when navigate to Masterdetailpage?
  • AsVAsV USMember ✭✭✭

    @JuniorJiang said:
    Yes @Thiyraash , MasterDetailPage is a root page.However this navigate can be designed by your logic.When launch application , first go to MasterDetailPage , then logic find no login , so change page to LoginPage( Push to LoginPage).When login successfully, pop to MasterDetailPage(LoginPage pop).

    First in MasterDetailPage:

    Navigation.PushAsync(new LoginPage ());

    Then back to MasterDetailPage:

    Navigation.PopAsync();
    

    Hi @JuniorJiang your idea is working fine but when I click on back button from LoginPage it is navigating to MasterDetailPage.My requirement is when I click on back button form LoginPage I want to get back from the application. Can you please help me for this?

    Thanks.

  • AsVAsV USMember ✭✭✭

    @JuniorJiang any help?

  • ThiyraashThiyraash Member ✭✭
    edited February 13
    On behind code of Login page. Override function called OnBackPressed()
    {return false}. This will disable the back pressed Of login page.
Sign In or Register to comment.