Skip to main content

Get Started with DevExpress Tabs for .NET MAUI: How to Specify Tabs in Markup

  • 3 minutes to read

This lesson explains how to use the TabView component with manually created tab items to implement bottom tab navigation in a .NET MAUI application:

.NET MAUI Tab View Getting Started - Add Tab Items

View Example

Create a New .NET MAUI Application and Add a Tab View

Create a new .NET MAUI solution.
Refer to Microsoft .NET Multi-platform App UI documentation for more information on how to get started with .NET MAUI.

Remove default content from the main page (MainPage.xaml) and event handlers from the code-behind file (MainPage.xaml.cs). Clear also the application’s resource dictionary (App.xaml).

Install the DevExpress.Maui.Controls package from your DevExpress NuGet feed.

In the MauiProgram.cs file, call the UseDevExpress method to register a handler for the TabView class:

using Microsoft.Maui;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Controls.Hosting;
using DevExpress.Maui.Controls;

namespace TabView_CreateItems {
    public static class MauiProgram {
        public static MauiApp CreateMauiApp() {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseDevExpress()
                .UseMauiApp<App>()
                .ConfigureFonts(fonts => {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                });
            return builder.Build();
        }
    }
}

In the MainPage.xaml file, use the dxco prefix to declare the DevExpress.Maui.Controls namespace and add a TabView object to the main page:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:dxco="clr-namespace:DevExpress.Maui.Controls;assembly=DevExpress.Maui.Controls"
             x:Class="TabView_CreateItems.MainPage">
     <dxco:TabView/>
</ContentPage>

Note

DevExpress Navigation Controls for .NET MAUI support iOS and Android. The project should contain only these platforms.

Create Tab Items

Add tab icons (.svg files) to the project and set their Build Action property to MauiImage. You can download images from Google Fonts or from the DevExpress Tab View for .NET MAUI example (see the following folder: ../CS/CreateTabItemsManually/TabView_CreateItems/Resources/Images/).

Add a new TabViewItem instance to the TabView.Items collection:

<dxco:TabView>
    <dxco:TabViewItem HeaderText="Mail"
                     HeaderIcon="mail.svg">
         <dxco:TabViewItem.Content>
            <Grid>
                <Label Text="Mail List Here" 
                       HorizontalOptions="Center" 
                       VerticalOptions="CenterAndExpand"/>
            </Grid>
         </dxco:TabViewItem.Content>
     </dxco:TabViewItem>
</dxco:TabView>

Note

You can skip the Items property tags in the XAML markup as this property has a ContentProperty attribute.

A tab item consists of the following elements:

  • Header - a tab displayed in the header panel. A header can display an icon and/or text to identify item content.
  • Content - a view assigned to TabViewItem.Content and displayed in the main area (in this example, a Grid with a Label).

MAUI Tab View - Tab Item

Add two more tab items:

<dxco:TabView>
    <dxco:TabViewItem HeaderText="Mail"
                     HeaderIcon="email.svg">
        <dxco:TabViewItem.Content>
            <Grid>
                <Label Text="Mail List Here" 
                       HorizontalOptions="Center" 
                       VerticalOptions="CenterAndExpand"/>
            </Grid>
        </dxco:TabViewItem.Content>
    </dxco:TabViewItem>

    <dxco:TabViewItem HeaderText="Calendar"
                     HeaderIcon="calendar.svg">
        <dxco:TabViewItem.Content>
            <Grid>
                <Label Text="Calendar Here" 
                       HorizontalOptions="Center" 
                       VerticalOptions="CenterAndExpand"/>
            </Grid>
        </dxco:TabViewItem.Content>
    </dxco:TabViewItem>

    <dxco:TabViewItem HeaderText="People"
                     HeaderIcon="people.svg">
        <dxco:TabViewItem.Content>
            <Grid>
                <Label Text="People Here"
                       HorizontalOptions="Center" 
                       VerticalOptions="CenterAndExpand"/>
            </Grid>
        </dxco:TabViewItem.Content>
    </dxco:TabViewItem>
</dxco:TabView>

.NET MAUI Tab View Getting Started - Tab Items

Customize the Tab View Appearance

Move the header panel with tabs to the bottom of the page, set up tabs to fill all the available space in the header panel, and hide the selected item indicator:

<dxco:TabView HeaderPanelPosition="Bottom"
             ItemHeaderWidth="*"
             IsSelectedItemIndicatorVisible="False">
    <!-- Tab items here. -->
</dxco:TabView>

.NET MAUI Tab View Getting Started - Bottom Tab Items

Specify icon and text colors for tabs in the header panel. Use properties of the TabView object to specify the same colors for all tab items when they are not selected, and properties of TabViewItem objects to set icon and text colors for individual tabs in the selected state:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TabView_CreateItems.MainPage"
             xmlns:dxco="clr-namespace:DevExpress.Maui.Controls;assembly=DevExpress.Maui.Controls">
    <ContentPage.Resources>
        <Color x:Key="unselected_grey">#757575</Color>
        <Color x:Key="mail_blue">#1e88e5</Color>
        <Color x:Key="calendar_green">#43a047</Color>
        <Color x:Key="people_red">#e53935</Color>
    </ContentPage.Resources>
    <dxco:TabView HeaderPanelPosition="Bottom"
                 IsSelectedItemIndicatorVisible="False"
                 ItemHeaderWidth="*"
                 ItemHeaderIconColor="{StaticResource unselected_grey}"
                 ItemHeaderTextColor="{StaticResource unselected_grey}">
        <dxco:TabViewItem HeaderText="Mail"
                         HeaderIcon="email.svg"
                         SelectedHeaderIconColor="{StaticResource mail_blue}"
                         SelectedHeaderTextColor="{StaticResource mail_blue}">
            <dxco:TabViewItem.Content>
                <Grid>
                    <Label Text="Mail List Here" 
                           HorizontalOptions="Center" 
                           VerticalOptions="CenterAndExpand"/>
                </Grid>
            </dxco:TabViewItem.Content>
        </dxco:TabViewItem>

        <dxco:TabViewItem HeaderText="Calendar"
                         HeaderIcon="calendar.svg"
                         SelectedHeaderIconColor="{StaticResource calendar_green}"
                         SelectedHeaderTextColor="{StaticResource calendar_green}">
            <dxco:TabViewItem.Content>
                <Grid>
                    <Label Text="Calendar Here" 
                           HorizontalOptions="Center" 
                           VerticalOptions="CenterAndExpand"/>
                </Grid>
            </dxco:TabViewItem.Content>
        </dxco:TabViewItem>

        <dxco:TabViewItem HeaderText="People"
                         HeaderIcon="people.svg"
                         SelectedHeaderIconColor="{StaticResource people_red}"
                         SelectedHeaderTextColor="{StaticResource people_red}">
            <dxco:TabViewItem.Content>
                <Grid>
                    <Label Text="People Here"
                           HorizontalOptions="Center" 
                           VerticalOptions="CenterAndExpand"/>
                </Grid>
            </dxco:TabViewItem.Content>
        </dxco:TabViewItem>
    </dxco:TabView>
</ContentPage>

.NET MAUI Tab View Getting Started - Tab Item Colors