Skip to content

Learn Mobile Development

Alamgeer's Blog

Menu
  • Home
  • Privacy Policy
Menu
DockLayout in MAUI

How to use DockLayout in MAUI

Posted on December 7, 2022January 18, 2023 by Learn Mobile Development

The Xamarin.CommunityToolkit DockLayout in MAUI is a layout where children can be docked to the sides of the layout container. Children are docked at one of 4 possible docking positions Top, Bottom, Left or Right. Child that are not explicitly docked or (with ‘None‘) are displayed at the center.

In this article, I’m going to show you how to use DockLayout in MAUI Community Toolkit.

Let’s Start

In this sample demo we will use CommunityToolkit.Maui nuget package.

CommunityToolkit.Maui

CommunityToolkit.Maui is a collection of Converters, Behaviours, Animations, Custom Views, Effects, Helpers etc. It simplifies the developers task when building Android, iOS, macOS and WinUI applications using MAUI.

1 – Install CommunityToolkit.Maui nuget package

Expander in MAUI

2 – In order to use the .NET MAUI Community Toolkit you need to call the extension method in your MauiProgram.cs file as follows:

using CommunityToolkit.Maui;
using Microsoft.Extensions.Logging;

namespace MAUIDockLayoutSample;

public static class MauiProgram
{
	public static MauiApp CreateMauiApp()
	{
		var builder = MauiApp.CreateBuilder();
		builder
			.UseMauiApp<App>()
			.UseMauiCommunityToolkit()
            .ConfigureFonts(fonts =>
			{
				fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
				fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
			});

#if DEBUG
		builder.Logging.AddDebug();
#endif

		return builder.Build();
	}
}

3 – Setting up the UI

3.1 – Create a MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             x:Class="MAUIDockLayoutSample.MainPage">

    <toolkit:DockLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">

        <StackLayout toolkit:DockLayout.DockPosition="Top" BackgroundColor="#ffcc61" HeightRequest="70"> 
            <Label Text="Header" TextColor="Black" FontSize="Large" FontAttributes="Bold" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
        </StackLayout>
        <StackLayout toolkit:DockLayout.DockPosition="Bottom" BackgroundColor="#cdaeb4" HeightRequest="70"> 
            <Label Text="Footer" TextColor="Black" FontSize="Large" FontAttributes="Bold" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
        </StackLayout>
         <StackLayout toolkit:DockLayout.DockPosition="Left" BackgroundColor="#83888e" WidthRequest="80"> 
            <Label Text="Left" TextColor="Black" FontSize="Large" FontAttributes="Bold" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
        </StackLayout>
         <StackLayout toolkit:DockLayout.DockPosition="Right" BackgroundColor="#abc8c2" WidthRequest="80" HorizontalOptions="FillAndExpand"> 
            <Label Text="Right" TextColor="Black" FontSize="Large" FontAttributes="Bold" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
        </StackLayout>
         <Image
             Source="dotnet_bot.png"
             HeightRequest="180"
             WidthRequest="180"
             HorizontalOptions="CenterAndExpand"
             VerticalOptions="CenterAndExpand"
             />
    </toolkit:DockLayout>
    
</ContentPage>

3.2 – MainPage.xaml.cs

namespace MAUIDockLayoutSample;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
	InitializeComponent();
    }
}

Now, We have completed the coding, Let’s try to run the application.

4 – Result

That’s all for now!

You can check the full source code here.

Happy Coding! 😀

You may also like

InternetConnStatus

How to check internet connection continuously in Xamarin Forms

Field Modifiers in MAUI

How to use Field Modifiers in MAUI

Post Views: 257
Share article with

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I'm Alamgeer Ashraf and having 9+ years of experience in enterprises mobile application development with Xamarin Native, Xamarin Forms & .Net MAUI.

Archives

  • February 2023 (1)
  • January 2023 (9)
  • December 2022 (5)
  • November 2022 (6)

Latest Posts

  • Prevent Dark Mode in Xamarin forms
    How to Prevent Dark Mode in Xamarin formsFebruary 3, 2023
  • apply color to Images
    How to apply color to Images and Icons in MAUIJanuary 30, 2023
  • iOS Large Page Title
    How to set iOS large page title in MAUIJanuary 26, 2023
  • Change StatusBar Color
    How to change StatusBar color in MAUIJanuary 22, 2023
  • Item reordering to CollectionView
    How to apply item reordering to CollectionView GridItemsLayout in MAUIJanuary 18, 2023

Popular Posts

  • How to apply color to Images and Icons in MAUI
  • How to use Expander in MAUI
  • How to use StateContainer in MAUI

Latest Comments

  1. Randyperly on How to use StateContainer in MAUIOctober 18, 2024

    very good _________________ netgame casino бездепозитный бонус

  2. SmiSew on How to use StateContainer in MAUIOctober 10, 2024

    Thanks for the post _________________ pin up casino бест

  3. StavkiTarve on How to use StateContainer in MAUIOctober 7, 2024

    interesting post _________________ слоты в 1xbet приложение

  4. Luke on How to use drag and drop gesture to CollectionView in MAUISeptember 25, 2024

    Thanks very much!

  5. Tony - Nhan Nguyen Lhoa Minh on How to apply item reordering to CollectionView GridItemsLayout in MAUIMarch 28, 2024

    That would be an amazing solution. It's easy to comprehend. Thank you very much.

Our Visitor

0 0 7 9 2 0
Users Today : 3
Users Yesterday : 1
Users Last 7 days : 24
Users Last 30 days : 122
Users This Month : 4
Total views : 14162
How to change StatusBar color in MAUI
Trending
How to change StatusBar color in MAUI

Category

  • .Net MAUI
  • MAUI Community Toolkit
  • MVVM
  • Xamarin Community Toolkit
  • Xamarin Forms

Contact Me

  • LinkedIn
      © 2025 Learn Mobile Development