Multiple app shells

Dani_S 3,336 Reputation points
2023-10-02T11:52:11.3566667+00:00

Hi,

In app.cs ctor i have condition to move to login through AppShell or to move to main page.

It possible to create new app shell and move to main page through this new app shell?

Thanks,

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,231 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,251 Reputation points Microsoft Vendor
    2023-10-03T03:09:09.1033333+00:00

    Hello,

    It possible to create new app shell and move to main page through this new app shell?

    Yes, you can use following code change MainPage to AppShell();

      App.Current.MainPage=new AppShell();
    

    For example, you judge the user if it is logining. If yes, open the AppShell, if not, open the loginpage.

     public App()
      {
          InitializeComponent();
         
          if (isLogin)
          {
              MainPage = new AppShell();
          }
          else
          {
              MainPage = new LoginPage();
          }
         
      }
    

    After login, you need to open the AppShell, for example, you can do this in the button click event.

    private void Button_Clicked(object sender, EventArgs e)
    {
            App.Current.MainPage=new AppShell();
    }
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful