Shell

This page describes how create a Shell in MauiReactor

.NET Multi-platform App UI (.NET MAUI) 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.

Official documentation: https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/ MauiReactor sample app: https://github.com/adospace/mauireactor-samples/tree/main/Controls/ShellTestPage https://github.com/adospace/mauireactor-samples/tree/main/Controls/ShellNavTestPage

Shell with ShellContents

The sample code below shows how to create a Shell with some pages using the ShellContent class:

class MainPageState
{
    public int Counter { get; set; }
}

class MainPage : Component<MainPageState>
{
    public override VisualNode Render()
        => new Shell
        {
            new ShellContent("Home")
                .Icon("home.png")
                .RenderContent(()=> new HomePage()),

            new ShellContent("Comments")
                .Icon("comments.png")
                .RenderContent(()=> new CommentsPage()),
        };
}

class HomePage : Component
{
    public override VisualNode Render()
    {
        return new ContentPage("Home")
        {
            new Label("Home")
                .VCenter()
                .HCenter()
        };
    }
}

class CommentsPage : Component
{
    public override VisualNode Render()
    {
        return new ContentPage("Comments")
        {
            new Label("Comments")
                .VCenter()
                .HCenter()
        };
    }
}
Shell in action in Android
Shell in action under Windows

Shell with Tab and FlyoutItem (AsMultipleItems)

Following it's another sample of Shell with more items arranged inside a FlyoutItem and Tab:

Shell under Windows
Shell under Android

Custom FlyoutItem appearance

In the following code, FlyoutItems appearance is customized:

Customized FlyoutItems

Custom FlyoutContent

You can also provide custom content for the Flyout as shown below:

Custom Shell FlyoutContent

Shell menu items

You can also create a simple menu item inside the shell with a custom command:

In the following sample code, we're going to customize the MenuItems:

Custom MenuItem

You can customize the flyout header and footer as well:

The following code uses the LinearGradient class provided by the MauiReactor framework ideal for describing a linear gradient brush in a single line

This is the resulting effect:

Custom Flyout Header and Footer + custom background

Tabs

You can create Tabs on top and bottom; just nest shell contents within Tab and TabBar objects as shown in the below example:

Shell top and bottom tab bar

You can also change tab bar properties like the background color or select a specific tab. The following code shows how to:

Custom tab bar color and selection of tab

To set an attached dependency property for a control in MauiReactor you have to use the Set() method.

For example, to set the TabBarIsVisible for a ShellContent use a code like this:

Set(MauiControls.Shell.TabBarIsVisibleProperty, true)

.NET Multi-platform App UI (.NET MAUI) Shell includes a URI-based navigation experience that uses routes to navigate to any page in the app, without having to follow a set navigation hierarchy. In addition, it also provides the ability to navigate backwards without having to visit all of the pages on the navigation stack.

MauiReactor allows the registration of components with routes just like you do with Page in normal Maui applications. To register a route you have to use the Routing.RegisterRoute<Component>("page name") method.

The following example shows how to register a few routes and how to navigate to them:

Shell navigation in action

Passing arguments to pages (components) would mean creating a Props class for the target page and using an overload of the GotoToAsync as shown below:

Passing arguments to pages

If you want to pass arguments to a modal page, use the overload of the Navigation.PushModalAsync<Page, Props>() method.

Shell TitleView

Shell control enables any View to be displayed in the navigation bar using the TitleView. In MauiReactor, you can set up a custom view using the TitleView fluent method of the ContentPage.

You can also customize the Window title with custom content. For more info, refer to the Window control page.

Last updated

Was this helpful?