Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The TitleBar control provides a simplified way to create a custom title bar for your app. The title bar is a fundamental component of a Windows app's user interface that identifies the app via its icon and title, houses the system caption buttons that let a user close, maximize, minimize, and restore the window, and lets a user drag the window around the screen.
You can use a custom title bar to better integrate the title bar area with your app UI. The title bar can be customized to match the app's visual style using Mica theming. It can include other relevant information, such as a document title or the current state (e.g., “Editing,” “Viewing,” etc.). It can also host other WinUI controls, like AutoSuggestBox and PersonPicture, providing a cohesive user experience for your app.
Is this the right control?
Use the TitleBar control when you want to integrate the title bar area with your app UI using customizations such as subtitles, Mica theming, and integrations with WinUI controls.
Anatomy
By default, the title bar shows only the system caption buttons. Other parts of the title bar are shown or hidden depending on associated property settings.
The title bar is divided into these areas:
- Back button: IsBackButtonEnabled, IsBackButtonVisible, BackRequested - A built-in back button for navigation.
- Pane toggle button: IsPaneToggleButtonVisible, PaneToggleRequested - This button is intended to be used in conjunction with the NavigationView control.
- Left header: LeftHeader
- Icon: IconSource
- Title: Title
- Subtitle: Subtitle
- Content: Content
- Right header: RightHeader
- Min drag region: This area is reserved next to the system caption buttons so that the user always has a place to grab the window for dragging.
- System caption buttons: These buttons are not part of the TitleBar control - it simply allocates space where the caption buttons appear, depending on RTL or LTR settings. Caption buttons and customizations are handled by the AppWindowTitleBar.
The layout is reversed when the FlowDirection is RightToLeft.
Create a title bar
- Important APIs: TitleBar class, Title property
The WinUI 3 Gallery app includes interactive examples of most WinUI 3 controls, features, and functionality. Get the app from the Microsoft Store or get the source code on GitHub
This example creates a simple title bar that replaces the system title bar. It has a title, icon, and Mica theming.
<Window
... >
<Window.SystemBackdrop>
<MicaBackdrop Kind="Base"/>
</Window.SystemBackdrop>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TitleBar x:Name="SimpleTitleBar"
Title="My App">
<TitleBar.IconSource>
<FontIconSource Glyph=""/>
</TitleBar.IconSource>
</TitleBar>
<!-- App content -->
<Frame x:Name="RootFrame" Grid.Row="1"/>
</Grid>
</Window>
public MainWindow()
{
this.InitializeComponent();
// Hides the default system title bar.
ExtendsContentIntoTitleBar = true;
// Replace system title bar with the WinUI TitleBar control.
SetTitleBar(SimpleTitleBar);
}
Integration with NavigationView
The Navigation view has a built-in back button and pane toggle button. Fluent Design guidance recommends that these controls be placed in the title bar when a custom title bar is used.
This example demonstrates how to integrate the TitleBar control with a NavigationView control by hiding the back button and pane toggle button in the navigation view and using the corresponding buttons on the title bar instead.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TitleBar Title="My App"
IsBackButtonVisible="True"
IsBackButtonEnabled="{x:Bind RootFrame.CanGoBack, Mode=OneWay}"
BackRequested="TitleBar_BackRequested"
IsPaneToggleButtonVisible="True"
PaneToggleRequested="TitleBar_PaneToggleRequested">
</TitleBar>
<NavigationView x:Name="RootNavigationView" Grid.Row="1"
IsBackButtonVisible="Collapsed"
IsPaneToggleButtonVisible="False">
<Frame x:Name="RootFrame" />
</NavigationView>
</Grid>
private void TitleBar_BackRequested(TitleBar sender, object args)
{
if (RootFrame.CanGoBack)
{
RootFrame.GoBack();
}
}
private void TitleBar_PaneToggleRequested(TitleBar sender, object args)
{
RootNavigationView.IsPaneOpen = !RootNavigationView.IsPaneOpen;
}
UWP and WinUI 2
The TitleBar control is not available for UWP and WinUI 2. Instead, see Title bar customization (UWP apps).
Related articles
Windows developer