Why do MAUI programs need AppShell?

Bruce 20 Reputation points
2023-04-25T07:52:05.3033333+00:00

I just learned MAUI development, I can see the project hierarchy after creating a new MAUI project: APP-AppShell-MainPage, if I don't AppShell this layer, the program can also run normally, as follows:

public partial class App : Application
{
	public App()
	{
		InitializeComponent();
		MainPage = new MainPage();
	}
}

My question is: What is the special purpose of this layer of AppShell and under what circumstances is it necessary to have AppShell?

Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2023-04-26T08:45:40.5433333+00:00

    Hello,

    App.MainPage property is to get or set the root page of the application. You can check the source code of Shell , it's derived from Page, MainPage is derived from Page as well. So, you can set MainPage = new MainPage() or MainPage = new AppShell() , the program can run normally.

    In addition, MainPage and AppShell are both created by the default MAUI template. You can also create other pages with different types, such as FlyoutPage, NavigationPage, TabbedPage. (MainPage is of type ContentPage) For more details, please refer to Controls - .NET MAUI | Microsoft Learn

    If you set MainPage as the root page, you cannot implement the navigation experience. If you want to go to another page from this MainPage, you may have to invoke INavigation.PushModalAsync method.

    What is the special purpose of this layer of AppShell and under what circumstances is it necessary to have AppShell?

    Shell reduces the complexity of app development by providing the fundamental features that most apps require, including:

    • A single place to describe the visual hierarchy of an app.
    • A common navigation user experience.
    • A URI-based navigation scheme that permits navigation to any page in the app.
    • An integrated search handler.

    For more details, please see .NET MAUI Shell overview - .NET MAUI | Microsoft Learn

    Best Regards,

    Wenyan Zhang


    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.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.