WinUI 3 – RelativePanel

RelativePanel

Overview

The RelativePanel layout container enables you to position child elements relative to each other using attached properties. It is ideal for creating adaptive UI that automatically arranges controls based on available space.

Getting Started

First, add the WinUI 3 NuGet package to your project and include the namespace:

<Page
    x:Class="MyApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyApp"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls">

Properties

PropertyDescription
AbovePositions the element above another element.
BelowPositions the element below another element.
AlignLeftWithAligns the left edge with another element.
AlignRightWithAligns the right edge with another element.
AlignTopWithAligns the top edge with another element.
AlignBottomWithAligns the bottom edge with another element.
AlignHorizontalCenterWithCenters horizontally with another element.
AlignVerticalCenterWithCenters vertically with another element.

Methods

RelativePanel does not expose specific methods; layout behavior is driven by attached properties.

Examples

Simple Form Layout

<muxc:RelativePanel Padding="24">
    <TextBlock x:Name="lblName" Text="Name:"/>
    <TextBox x:Name="txtName" Width="200"
             muxc:RelativePanel.RightOf="lblName"
             Margin="8,0,0,0"/>

    <TextBlock x:Name="lblEmail" Text="Email:"
             muxc:RelativePanel.Below="lblName"
             Margin="0,16,0,0"/>
    <TextBox x:Name="txtEmail" Width="200"
             muxc:RelativePanel.RightOf="lblEmail"
             muxc:RelativePanel.Below="txtName"
             Margin="8,16,0,0"/>

    <Button Content="Submit"
            muxc:RelativePanel.AlignHorizontalCenterWith="txtEmail"
            muxc:RelativePanel.Below="txtEmail"
            Margin="0,24,0,0"/>
</muxc:RelativePanel>

The example arranges labels and text boxes using RightOf and Below attached properties, keeping the form compact and responsive.

API Reference