.NET MAUI Documentation

Learn about building cross-platform applications with .NET MAUI.

DockLayout

The DockLayout is a layout panel that allows you to dock child elements to the top, bottom, left, right, or fill the remaining space within the layout.

Overview

When arranging child elements, the DockLayout prioritizes elements docked to the edges (top, bottom, left, right) and then places the remaining element in the fill area. If multiple elements are docked to the same edge, they will be arranged sequentially along that edge.

Properties

The DockLayout itself doesn't expose many direct properties for arranging children, as the positioning is controlled by the Dock attached property set on each child element.

Attached Properties

The key to using DockLayout is the Dock attached property. This property can be set on any child element of a DockLayout to specify its position.

XAML Example

Here's a common scenario demonstrating how to use DockLayout with various dock positions:

<DockLayout xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                        x:Class="MyMauiApp.DockLayoutPage"
                        HeightRequest="300" >

                <Label Text="Top Banner"
                       DockLayout.Dock="Top"
                       BackgroundColor="LightBlue"
                       HorizontalOptions="Fill"
                       HeightRequest="50" />

                <Button Text="OK"
                        DockLayout.Dock="Bottom"
                        BackgroundColor="LightGreen"
                        HorizontalOptions="Center"
                        Margin="10" />

                <Label Text="Left Navigation"
                       DockLayout.Dock="Left"
                       BackgroundColor="LightCoral"
                       WidthRequest="100" />

                <Label Text="Right Sidebar"
                       DockLayout.Dock="Right"
                       BackgroundColor="LightYellow"
                       WidthRequest="120" />

                <Label Text="Main Content Area"
                       DockLayout.Dock="Fill"
                       BackgroundColor="LightGray"
                       Padding="10" />
            </DockLayout>

Visual Representation

The following is a visual representation of how the elements would be arranged in the XAML example above:

Top Banner
OK
Left Navigation
Right Sidebar
Main Content Area

Considerations

Note: When using DockLayout, ensure that child elements have appropriate sizing (e.g., HeightRequest for top/bottom, WidthRequest for left/right) or that they can size themselves correctly to avoid unexpected layout behavior. The Fill element will automatically take up the remaining space.