Get Started with Shell Using .NET MAUI Preview 12 | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (215)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (915)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (628)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (592)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Get Started with Shell Using .NET MAUI Preview 12

Get Started with Shell Using .NET MAUI Preview 12

As you may know, since 2021, .NET MAUI Preview is updated in the middle of every month. On Jan. 19, 2022, Microsoft released the update .NET MAUI Preview 12. I was really surprised to get an update on the Shell application in .NET MAUI Preview 12. In this blog, let’s see how easy it is to integrate Shell in a .NET MAUI application (.NET MAUI Preview 12).

.NET MAUI Preview 12 Overview

.NET Multi-platform App UI (MAUI) released Preview 12 with many quality improvements and several new features:

  • Documentation was added for apps (icons and lifecycle), brushes, and controls.
  • RelativeLayout and AbsoluteLayout compatibility handlers.
  • Z-index support for multiple-child layout.
  • Windows extended toolbar—non-Shell.

The Shell feature is available in .NET MAUI Preview 12, so please ensure your Visual Studio 2022 is updated. For more details, please refer to the article, .NET MAUI Preview 12. Also, check the .NET MAUI Preview 12 release notes.

Easily build cross-platform mobile and desktop apps with the flexible and feature-rich controls of the Syncfusion .NET MAUI platform.

How to Use Shell in .NET MAUI Preview 12

Shell is basically an app scaffold designed with flyout menus and tabs. It is commonly named AppShell and can hold collections of pages. It will save you development time by reducing UI complexities, providing fundamental features like navigation and search.
Follow these steps to use Shell in .NET MAUI:

Step 1: First, create required content pages. I am going to show information for three authors on a tabbed page. To create a content page, right-click on the solution. Click Add, and then New Item. Select ContentPage or press Ctrl + Alt + a to create a new page. I am naming this content page SebastianInfoPage.

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiShell.SebastianInfoPage"
             Title="SebastianInfoPage"
             BackgroundColor="White">
  <StackLayout Orientation="Vertical" Margin="20">
    <Label Text="Sebastian"
           FontSize="24"
           FontAttributes="Bold"
           VerticalOptions="CenterAndExpand"
           HorizontalOptions="CenterAndExpand" />
    <Image Source="sebastian.png"
           HeightRequest="250"
           WidthRequest="250"
           VerticalOptions="CenterAndExpand"
           HorizontalOptions="CenterAndExpand" />
    <Label Text="Author"
           FontSize="12"
           FontAttributes="Bold"
           VerticalOptions="CenterAndExpand"
           HorizontalOptions="CenterAndExpand" />
    <Label Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."
           FontSize="12"
           VerticalOptions="CenterAndExpand"
           HorizontalOptions="CenterAndExpand" />
  </StackLayout>
</ContentPage>

Repeat this step twice to create two more author info pages, mine being NoraInfoPage and WashingtonInfoPage.

On each page, I have created a UI to show author details using labels (to show the name and description of the authors) and images (to show avatar images of the authors).

Step 2: Now, create another XAML content page by right-clicking the solution. Click Add, then New Item, and ContentPage. Name this content page AppShell.Xaml.

Step 3: Then, change the content page created in the previous step to a Shell page. Refer to the following code.

<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       x:Class="MauiShell.AppShell"
       xmlns:Pages="clr-namespace:MauiShell"
       Title="AppShell"
       BackgroundColor="White"></Shell>

Change the content page into a Shell page in code behind, too.

public partial class AppShell : Shell
{
  public AppShell()
  {
    InitializeComponent();
  }
}

Step 4: In the Shell page, create a TabBar and add the required tabs with Title and Icon properties. Here, each tab is designed to hold one page.

<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       x:Class="MauiShell.AppShell"
       xmlns:Pages="clr-namespace:MauiShell"
       Title="AppShell"
       BackgroundColor="White">
  <TabBar>
    <Tab Title="Sebastian"
         Icon="sebastian.png">
    </Tab>
    <Tab Title="Washington"
         Icon="washington.png">
    </Tab>
    <Tab Title="Nora"
         Icon="nora.png">
    </Tab>
  </TabBar>
</Shell>

Step 5: Then, add ShellContent inside each tab and set the ContentTemplate of the ShellContent to the info pages we created in Step 1.

<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       x:Class="MauiShell.AppShell"
       xmlns:Pages="clr-namespace:MauiShell"
       Title="AppShell"
       BackgroundColor="White">
  <TabBar>
    <Tab Title="Sebastian"
         Icon="sebastian.png">
      <ShellContent ContentTemplate="{DataTemplate Pages:SebastianInfoPage}" />
    </Tab>
    <Tab Title="Washington"
         Icon="washington.png">
      <ShellContent ContentTemplate="{DataTemplate Pages:WashingtonInfoPage}" />
    </Tab>
    <Tab Title="Nora"
         Icon="nora.png">
      <ShellContent ContentTemplate="{DataTemplate Pages:NoraInfoPage}" />
    </Tab>
  </TabBar>
</Shell>

That’s it. Execute the project and you will see output like in the following screenshot.

Shell in .NET MAUI Preview 12
Shell in .NET MAUI Preview 12

Syncfusion .NET MAUI controls are well-documented, which helps to quickly get started and migrate your Xamarin apps.

Add Shell Flyout View

In MAUI Preview 12, you can show a page as a flyout menu. To do this, remove the TabBar and Tab. Then, add the ShellContent directly to the content of the Shell.

You need to provide a title for the ShellContent. The value provided to the title will be shown in the flyout menu. You can also add any view as the header of the flyout by using the FlyoutHeader property of the Shell.

Refer to the following code.

<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       x:Class="MauiShell.AppShell"
       xmlns:Pages="clr-namespace:MauiShell"
       Title="AppShell"
       BackgroundColor="White">
  <Shell.FlyoutHeader>
    <Grid>
    <Image Source="dotnet_bot.png"
          HeightRequest="142"
          VerticalOptions="Center"
          WidthRequest="230"
          HorizontalOptions="Center" />
    </Grid>
  </Shell.FlyoutHeader>
  <ShellContent Title="Sebastian" ContentTemplate="{DataTemplate Pages:SebastianInfoPage}" />
  <ShellContent Title="Washington" ContentTemplate="{DataTemplate Pages:WashingtonInfoPage}" />
  <ShellContent Title="Nora" ContentTemplate="{DataTemplate Pages:NoraInfoPage}" />
</Shell>

Now, execute the project and you will see output like in the following screenshot.

Shell with Flyout in .NET MAUI Preview 12
Shell with Flyout in .NET MAUI Preview 12

Navigation in .NET MAUI Shell

You can use navigation support in Shell in .NET MAUI Preview 12. Navigation uses URI-based routing, and you need to register the routes to navigate among them. Along with URL, navigation progress in a Shell application also requires a:

  • RouteThe path to the content is determined by the Shell visual hierarchy.
  • PagePage can be pushed and popped onto the navigation stack of the Shell visual hierarchy.
  • ParametersQuery parameters that can be passed to the destination page when you navigate from one page to another.

Registering routes in Shell navigation

In Shell, you can register the routes explicitly for any pages that are not actually presented in the Shell visual hierarchy. To achieve this, use the Routing.RegisterRoute method, as shown in the following code.

Routing.RegisterRoute(nameof(SebastianInfoPage), typeof(SebastianInfoPage));
Routing.RegisterRoute(nameof(WashingtonInfoPage), typeof(WashingtonInfoPage));
Routing.RegisterRoute(nameof(NoraInfoPage), typeof(NoraInfoPage));

Shell and Dependency Injection

To simplify accessing the ViewModels, you can inject the ViewModel in the main page using dependency injection. That way, an object receives other objects. Dependency injection is a version of the inversion of control pattern. The service class will inject dependencies into an object at runtime. You can learn how to use dependency injection in .NET MAUI here.

To make it easy for developers to include Syncfusion .NET MAUI controls in their projects, we have shared some working ones.

Syncfusion .NET MAUI Controls Compatible with .NET MAUI Preview 12

Syncfusion .NET MAUI controls are now compatible with .NET MAUI Preview 12. You can install our control package (latest version 19.4.48-preview) from nuget.org and use it in your application. Currently, Syncfusion offers nine controls: Cartesian Chart, Circular Chart, Scheduler, ListView, Tab View, Radial Gauge, Slider, RangeSlider, Badge View, and Effects View. The suite also supports file-format libraries for Excel, PDF, Word, and PowerPoint files. Check out our .NET MAUI controls road map for plans for our upcoming 2022 Volume 2 release and find more on our controls in their documentation.

Conclusion

I hope you enjoyed this blog and thanks for reading! Now you know how easy it is to work on a .NET MAUI Shell application. For more details, please refer to the article, .NET MAUI Preview 12. Also, check out the .NET MAUI Preview 12 release notes.

As I said, our controls are compatible with .NET MAUI Preview 12, so you can use them in your .NET MAUI Shell application. We are working every quarter to deliver more .NET MAUI controls to replace our existing Xamarin.Forms controls, so you can use them if you migrate your Xamarin.Forms Shell projects to .NET MAUI projects. If you have any feedback, special requirements, or controls that you’d like to see in our .NET MAUI suite, please let us know in the comments section below.

Also, you can contact us through our support forumsupport portal, or feedback portal. We are always happy to assist you!

Test Flight
App Center Badge
Google Play Store Badge
Microsoft Badge
Github Store Badge

Related blogs

Tags:

Share this post:

Comments (2)

Do you have an example using the Syncfusion version of TabBar with shell?

Thanks

Selva Ganapathy Kathiresan
Selva Ganapathy Kathiresan

Hi K. CARTER,

Syncfusion .NET MAUI Tab view is a content view control and don’t have support to load page (Shell) as tab item content. As a result, Tab View is unable to meet your requirements at this time.

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed