Title bar customization

Windows provides a default title bar for every window and lets you to customize information technology to match the personality of your app. The default championship bar comes with some standard components and core functionality such as dragging and resizing the window.

A Windows app showing the title bar

See the Title bar pattern article for guidance on customizing your app's title bar, acceptable title bar surface area content, and recommended UI patterns.

Title bar components

This list describes the components of the standard title bar.

  • Title bar rectangle
  • Title text
  • System icon (except for UWP)
  • System menu - accessed by clicking the app icon or correct-clicking the championship bar
  • Caption controls
    • Minimize button
    • Maximize/Restore push
    • Close button

Platform options

The exact features of the title bar and the options available to customize it depend on your UI platform and app requirements. This article shows how to customize the title bar for apps that use either the Windows App SDK, WinUI 3, or UWP with WinUI 2.

  • Windows App SDK
  • WinUI 3
  • UWP/WinUI 2
  • Applies to: Windows App SDK
  • Important APIs: AppWindow.TitleBar property, AppWindowTitleBar form, AppWindow course

Windowing functionality in the Windows App SDK is through the Microsoft.UI.Windowing.AppWindow class, which is based on the Win32 HWND model. In that location'southward a i:1 mapping between an AppWindow and a summit-level HWND in your app. AppWindow and its related classes provide APIs that let you manage many aspects of your app's elevation-level windows, including customization of the championship bar. You can modify the default title bar that Windows provides so that it blends with the rest of your UI, or extend your app canvas into the title bar area and provide your own title bar content.

Important

Title bar customization APIs are currently supported on Windows 11 only. Nosotros recommend that yous check AppWindowTitleBar.IsCustomizationSupported in your code before you telephone call these APIs to ensure your app doesn't crash on other versions of Windows.

For XAML apps that use WinUI 3, XAML Window APIs provide a simpler way to customize the title bar that also works on Windows ten. These APIs can be used in conjunction with the Windows App SDK APIs (see the WinUI 3 tab).

How to work with AppWindow

You can use AppWindow APIs with any UI framework that the Windows App SDK supports - Win32, WPF, WinForms, or WinUI three - and you tin adopt them incrementally, using only the APIs y'all need. You become an AppWindow object from an existing window using the interop APIs. With this AppWindow object y'all have access to the title bar customization APIs. For more about the interop APIs, run into Manage app windows - UI framework and HWND interop and the Windowing gallery sample.

How much to customize the title bar

At that place are two levels of customization that you can utilize to the championship bar: utilise minor modifications to the default title bar, or extend your app canvas into the title bar expanse and provide completely custom content.

Simple

Simple customization is but available for Windows App SDK and UWP/WinUI 2.

For simple customization, such equally changing the championship bar color, yous tin can ready properties on your app window'due south championship bar object to specify the colors you want to apply for title bar elements. In this case, the system retains responsibility for all other aspects of the title bar, such as cartoon the app title and defining drag areas.

Full

Your other option is to hide the default championship bar and supersede it with your own custom content. For example, you can place text, a search box, or custom menus in the championship bar area. Y'all will likewise demand to apply this pick to extend a material backdrop, similar Mica, into the title bar area.

When you opt for full customization, y'all are responsible for putting content in the championship bar area, and you can define your own elevate region. The caption controls (system Close, Minimize, and Maximize buttons) are still bachelor and handled by the system, but elements similar the app title are not. Yous will need to create those elements yourself as needed by your app.

Simple customization

If yous want only to customize the title bar colors or icon, y'all tin ready properties on the title bar object for your app window.

  • Windows App SDK
  • WinUI 3
  • UWP/WinUI two

(Windows 11 only. Run into Platform options for more info.)

These examples show how to become an instance of AppWindow and set its properties.

Title

By default, the title bar shows the app type every bit the window title (for case, "WinUI Desktop"). To change the window championship, prepare the AppWindow.Title belongings to a single-line text value.

                  using Microsoft.UI;           // Needed for WindowId. using Microsoft.UI.Windowing; // Needed for AppWindow. using WinRT.Interop;          // Needed for XAML/HWND interop.  private AppWindow m_AppWindow;  public MainWindow() {     this.InitializeComponent();      m_AppWindow = GetAppWindowForCurrentWindow();     m_AppWindow.Title = "App title"; }  private AppWindow GetAppWindowForCurrentWindow() {     IntPtr hWnd = WindowNative.GetWindowHandle(this);     WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);     return AppWindow.GetFromWindowId(wndId); }                                  

Colors

This example shows how to get an example of AppWindowTitleBar and set its colour properties.

                  private bool SetTitleBarColors() {     // Check to run across if customization is supported.     // Currently simply supported on Windows xi.     if (AppWindowTitleBar.IsCustomizationSupported())     {         if (m_AppWindow is naught)         {             m_AppWindow = GetAppWindowForCurrentWindow();         }         var titleBar = m_AppWindow.TitleBar;          // Set agile window colors         titleBar.ForegroundColor = Colors.White;         titleBar.BackgroundColor = Colors.Light-green;         titleBar.ButtonForegroundColor = Colors.White;         titleBar.ButtonBackgroundColor = Colors.SeaGreen;         titleBar.ButtonHoverForegroundColor = Colors.Gainsboro;         titleBar.ButtonHoverBackgroundColor = Colors.DarkSeaGreen;         titleBar.ButtonPressedForegroundColor = Colors.Gray;         titleBar.ButtonPressedBackgroundColor = Colors.LightGreen;          // Set up inactive window colors         titleBar.InactiveForegroundColor = Colors.Gainsboro;         titleBar.InactiveBackgroundColor = Colors.SeaGreen;         titleBar.ButtonInactiveForegroundColor = Colors.Gainsboro;         titleBar.ButtonInactiveBackgroundColor = Colors.SeaGreen;         return true;     }     return false; }                                  

Icon and system menu

You can also hide the system icon, or replace information technology with a custom icon. The system icon shows the organisation menu when right clicked or tapped one time. It closes the window when double clicked/tapped.

To bear witness or hide the system icon and associated behaviors, set the championship bar IconShowOptions property.

                  titleBar.IconShowOptions = IconShowOptions.HideIconAndSystemMenu;                                  

Note

The IconShowOptions enumeration allows the possibility of other options being added in futurity releases. You tin requite u.s.a. feedback on the Windows App SDK repository on GitHub if this is of interest to you.

To employ a custom window icon, call one of the AppWindow.SetIcon methods to set the new icon.

  • SetIcon(String)

    The SetIcon(Cord) method currently works only with .ico files. The string y'all laissez passer to this method is the fully qualified path to the .ico file.

                          m_AppWindow.SetIcon("iconPath/iconName.ico");                                          
  • SetIcon(IconId)

    If yous already have a handle to an icon (HICON) from one of the Icon functions like CreateIcon, you can utilise the GetIconIdFromIcon interop API to go an IconId. You can then pass the IconId to the SetIcon(IconId) method to set your window icon.

                          m_AppWindow.SetIcon(iconId));                                          

In that location are a few things to exist enlightened of when setting title bar colors:

  • The push button groundwork color is not applied to the close push button hover and pressed states. The close push always uses the system-defined color for those states.
  • Setting a color holding to cypher resets it to the default system color.
  • You can't set transparent colors. The color's alpha channel is ignored.

Windows gives a user the option to apply their selected accent color to the title bar. If you set any championship bar colour, we recommend that you lot explicitly set all the colors. This ensures that there are no unintended color combinations that occur because of user defined color settings.

Full customization

When you opt-in to full title bar customization, your app's client area is extended to encompass the unabridged window, including the title bar area. You lot are responsible for drawing and input-handling for the entire window except the explanation buttons, which are withal provided by the window.

To hide the default title bar and extend your content into the title bar expanse, prepare the belongings that extends app content into the championship bar surface area to true. In a XAML app, this property can exist set in your app's OnLaunched method (App.xaml.cs), or in your app's first page.

  • Windows App SDK
  • WinUI three
  • UWP/WinUI 2

(Windows 11 only. Run into Platform options for more than info.)

This case shows how to get the AppWindowTitleBar and set the ExtendsContentIntoTitleBar property to true.

Important

Championship bar customization APIs are not supported on all versions of Windows where your app might run, so be sure to cheque AppWindowTitleBar.IsCustomizationSupported in your code earlier you call these APIs. If title bar customization is non supported, yous will typically hibernate your custom title bar UI past setting Visibility to Collapsed.

                  using Microsoft.UI;           // Needed for WindowId using Microsoft.UI.Windowing; // Needed for AppWindow using WinRT.Interop;          // Needed for XAML/HWND interop  private AppWindow m_AppWindow;  public MainWindow() {     this.InitializeComponent();      m_AppWindow = GetAppWindowForCurrentWindow();     // Bank check to see if customization is supported.     // Currently only supported on Windows 11.     if (AppWindowTitleBar.IsCustomizationSupported())     {         var titleBar = m_AppWindow.TitleBar;         // Hide default championship bar.         titleBar.ExtendsContentIntoTitleBar = truthful;     }     else     {         // Championship bar customization using these APIs is currently         // supported only on Windows eleven. In other cases, hibernate         // the custom title bar chemical element.         AppTitleBar.Visibility = Visibility.Collapsed;     } }  private AppWindow GetAppWindowForCurrentWindow() {     IntPtr hWnd = WindowNative.GetWindowHandle(this);     WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);     return AppWindow.GetFromWindowId(wndId); }                                  

Championship bar content and drag regions

When your app is extended into the title bar area, you're responsible for defining and managing the UI for the title bar. This typically includes, at a minimum, specifying championship text and the drag region. The drag region of the championship bar defines where the user can click and elevate to move the window effectually. It's too where the user can right-click to show the organization menu.

To learn more about acceptable title bar content and recommended UI patterns, see Championship bar design.

  • Windows App SDK
  • WinUI 3
  • UWP/WinUI 2

(Windows 11 merely. See Platform options for more info.)

When you extend your content into the title bar area, the arrangement by default retains the entire title bar expanse except for the caption buttons as the drag region. If yous don't identify interactive content in your title bar, you can leave this default elevate region as-is. If you place interactive content in your title bar, you lot demand to specify the drag regions, which we encompass in the adjacent section.

This example shows the XAML for a custom title bar UI without interactive content.

                  <Grid 10:Proper name="AppTitleBar"         Meridian="32">     <Grid.ColumnDefinitions>         <ColumnDefinition x:Proper noun="LeftPaddingColumn" Width="0"/>         <ColumnDefinition/>         <ColumnDefinition x:Proper noun="RightPaddingColumn" Width="0"/>     </Grid.ColumnDefinitions>     <Epitome ten:Name="TitleBarIcon" Source="/Images/WindowIcon.png"            Grid.Column="ane"            HorizontalAlignment="Left"            Width="xvi" Height="sixteen"            Margin="eight,0,0,0"/>     <TextBlock 10:Name="TitleTextBlock"                 Text="App title"                 Style="{StaticResource CaptionTextBlockStyle}"                Grid.Column="i"                VerticalAlignment="Center"                Margin="28,0,0,0"/> </Filigree>                                  

Of import

The LeftPaddingColumn and RightPaddingColumn are used to reserve space for the caption buttons. The Width values for these columns are set in code, which is shown later. Run across the System caption buttons section for the code and explanation.

Interactive content

You can place interactive controls, similar buttons, menus, or a search box, in the elevation part of the app so they appear to be in the title bar. Notwithstanding, there are a few rules you must follow to ensure that your interactive elements receive user input while all the same allowing users to move your window around.

A Windows app with a search box in the title bar

  • Windows App SDK
  • WinUI 3
  • UWP/WinUI 2

(Windows 11 only. Run into Platform options for more info.)

If you add together interactive content in the title bar expanse, y'all should ascertain explicit elevate regions effectually that content so that users can interact with it. Afterward you ready a custom drag region, the default drag region is removed and the arrangement does not reserve whatever mandatory drag region. Yous are responsible for ensuring that in that location is enough infinite in your title bar for your users to move your window.

To set the drag regions, call the AppWindowTitleBar.SetDragRectangles method. This method takes an array of rectangles, each of which defines a drag region. When the size of the title bar changes, you need to recalculate the drag regions to match the new size, and call SetDragRectangles with the new values.

Your custom title bar volition not exist shown if it's not supported on the arrangement where it's run. Y'all should provide an alternative UI for whatsoever functionality that you placed in your custom title bar.

This case shows a custom championship bar UI with a search box and demonstrates how to calculate and set the drag rectangles on either side of the search box. Here are a few important points to notice in the code.

  • Set the AppTitleBar Grid tiptop to 48 to follow the Title bar design guidance for interactive content.
  • To brand calculating the drag rectangles easier, utilize a Grid with multiple named columns for the layout.
  • Ready ExtendsContentIntoTitleBar to true in the MainWindow constructor. If y'all set information technology in code that gets called afterward, the default organization title bar might be shown beginning, and then hidden.
  • Make the initial call to summate drag regions afterward the AppTitleBar chemical element has loaded (AppTitleBar_Loaded). Otherwise, there's no guarantee that the elements used for the calculation will accept their correct values.
  • Update the drag rectangle calculations simply subsequently the AppTitleBar chemical element has changed size (AppTitleBar_SizeChanged). If you lot depend on the window Changed outcome, there will be situations (like window maximize/minimize) where the result occurs before AppTitleBar is resized and the calculations will apply wrong values.
  • Call SetDragRectangles just after you bank check IsCustomizationSupported and ExtendsContentIntoTitleBar to confirm that a custom title bar is supported and being used.
                  <Filigree x:Proper name="AppTitleBar"         Meridian="48">     <Filigree.ColumnDefinitions>         <ColumnDefinition ten:Name="LeftPaddingColumn" Width="0"/>         <ColumnDefinition x:Proper noun="IconColumn" Width="Auto"/>         <ColumnDefinition 10:Proper noun="TitleColumn" Width="Automobile"/>         <ColumnDefinition ten:Name="LeftDragColumn" Width="*"/>         <ColumnDefinition 10:Proper name="SearchColumn" Width="Motorcar"/>         <ColumnDefinition 10:Name="RightDragColumn" Width="*"/>         <ColumnDefinition ten:Name="RightPaddingColumn" Width="0"/>     </Grid.ColumnDefinitions>     <Image x:Name="TitleBarIcon" Source="/Images/WindowIcon.png"            Grid.Cavalcade="one"            Width="xvi" Height="sixteen"            Margin="8,0,0,0"/>     <TextBlock x:Proper noun="TitleTextBlock"                 Text="App championship"                 Fashion="{StaticResource CaptionTextBlockStyle}"                Grid.Column="2"                VerticalAlignment="Middle"                Margin="iv,0,0,0"/>     <AutoSuggestBox Grid.Cavalcade="4" QueryIcon="Detect"                     PlaceholderText="Search"                     VerticalAlignment="Center"                     Width="260" Margin="4,0"/> </Filigree>                                  
                  using System.Runtime.InteropServices;  private AppWindow m_AppWindow;  public MainWindow() {     this.InitializeComponent();      m_AppWindow = GetAppWindowForCurrentWindow();      // Cheque to encounter if customization is supported.     // Currently merely supported on Windows 11.     if (AppWindowTitleBar.IsCustomizationSupported())     {         var titleBar = m_AppWindow.TitleBar;         titleBar.ExtendsContentIntoTitleBar = true;         AppTitleBar.Loaded += AppTitleBar_Loaded;         AppTitleBar.SizeChanged += AppTitleBar_SizeChanged;     }     else     {         // Title bar customization using these APIs is currently         // supported just on Windows 11. In other cases, hide         // the custom title bar element.         AppTitleBar.Visibility = Visibility.Collapsed;          // Show alternative UI for any functionality in         // the title bar, such as search.     }  }  private void AppTitleBar_Loaded(object sender, RoutedEventArgs east) {     // Bank check to see if customization is supported.     // Currently only supported on Windows 11.     if (AppWindowTitleBar.IsCustomizationSupported())     {         SetDragRegionForCustomTitleBar(m_AppWindow);     } }  private void AppTitleBar_SizeChanged(object sender, SizeChangedEventArgs e) {     // Check to run across if customization is supported.     // Currently merely supported on Windows xi.     if (AppWindowTitleBar.IsCustomizationSupported()         && m_AppWindow.TitleBar.ExtendsContentIntoTitleBar)     {         // Update drag region if the size of the title bar changes.         SetDragRegionForCustomTitleBar(m_AppWindow);     } }  private AppWindow GetAppWindowForCurrentWindow() {     IntPtr hWnd = WindowNative.GetWindowHandle(this);     WindowId wndId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);     return AppWindow.GetFromWindowId(wndId); }  [DllImport("Shcore.dll", SetLastError = true)] internal static extern int GetDpiForMonitor(IntPtr hmonitor, Monitor_DPI_Type dpiType, out uint dpiX, out uint dpiY);  internal enum Monitor_DPI_Type : int {     MDT_Effective_DPI = 0,     MDT_Angular_DPI = one,     MDT_Raw_DPI = 2,     MDT_Default = MDT_Effective_DPI }  private double GetScaleAdjustment() {     IntPtr hWnd = WindowNative.GetWindowHandle(this);     WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);     DisplayArea displayArea = DisplayArea.GetFromWindowId(wndId, DisplayAreaFallback.Primary);     IntPtr hMonitor = Win32Interop.GetMonitorFromDisplayId(displayArea.DisplayId);      // Go DPI.     int issue = GetDpiForMonitor(hMonitor, Monitor_DPI_Type.MDT_Default, out uint dpiX, out uint _);     if (event != 0)     {         throw new Exception("Could non become DPI for monitor.");     }      uint scaleFactorPercent = (uint)(((long)dpiX * 100 + (96 >> i)) / 96);     return scaleFactorPercent / 100.0; }  private void SetDragRegionForCustomTitleBar(AppWindow appWindow) {     // Check to see if customization is supported.     // Currently but supported on Windows xi.     if (AppWindowTitleBar.IsCustomizationSupported()         && appWindow.TitleBar.ExtendsContentIntoTitleBar)     {         double scaleAdjustment = GetScaleAdjustment();          RightPaddingColumn.Width = new GridLength(appWindow.TitleBar.RightInset / scaleAdjustment);         LeftPaddingColumn.Width = new GridLength(appWindow.TitleBar.LeftInset / scaleAdjustment);          List<Windows.Graphics.RectInt32> dragRectsList = new();          Windows.Graphics.RectInt32 dragRectL;         dragRectL.10 = (int)((LeftPaddingColumn.ActualWidth) * scaleAdjustment);         dragRectL.Y = 0;         dragRectL.Pinnacle = (int)(AppTitleBar.ActualHeight * scaleAdjustment);         dragRectL.Width = (int)((IconColumn.ActualWidth                                 + TitleColumn.ActualWidth                                 + LeftDragColumn.ActualWidth) * scaleAdjustment);         dragRectsList.Add(dragRectL);          Windows.Graphics.RectInt32 dragRectR;         dragRectR.X = (int)((LeftPaddingColumn.ActualWidth                             + IconColumn.ActualWidth                             + TitleTextBlock.ActualWidth                             + LeftDragColumn.ActualWidth                             + SearchColumn.ActualWidth) * scaleAdjustment);         dragRectR.Y = 0;         dragRectR.Height = (int)(AppTitleBar.ActualHeight * scaleAdjustment);         dragRectR.Width = (int)(RightDragColumn.ActualWidth * scaleAdjustment);         dragRectsList.Add together(dragRectR);          Windows.Graphics.RectInt32[] dragRects = dragRectsList.ToArray();          appWindow.TitleBar.SetDragRectangles(dragRects);     } }                                  

Warning

AppWindow uses concrete pixels for compatibility with UI frameworks that don't use logical coordinates. If you use WPF or WinUI 3, RightInset, LeftInset, and the values passed to SetDragRectangles need to be adjusted if the brandish scale is not 100%. In this example, we calculate a scaleAdjustment value to account for the display scale setting.

For WPF, you tin can handle the Window.DpiChanged event to get the NewDpi value.

For WinUI iii, employ Platform Invoke (P/Invoke) to call the native GetDpiForMonitor role, equally shown in the preceding example.

Tip

Y'all can go the elevation of the organisation TitleBar (int titleBarHeight = appWindow.TitleBar.Pinnacle;) and utilise that to prepare the top of your custom title bar and drag regions. However, the blueprint guidance recommends setting the title bar height to 48px if you add other controls. In this case, the peak of the arrangement championship bar will not match your content, so instead, utilise the ActualHeight of the championship bar element to set the elevate region height.

System caption buttons

  • Windows App SDK
  • WinUI 3
  • UWP/WinUI 2

(Windows 11 simply. See Platform options for more info.)

The arrangement reserves the upper-left or upper-correct corner of the app window for the system explanation buttons (minimize, maximize/restore, close). The organisation retains command of the caption push button area to guarantee that minimum functionality is provided for dragging, minimizing, maximizing, and endmost the window. The system draws the Close push button in the upper-right for left-to-right languages and the upper-left for correct-to-left languages.

Yous can draw content underneath the explanation control expanse, such as your app background, just yous should not put any UI that you expect the user to exist able to interact with. It does not receive whatever input considering input for the caption controls is handled by the system.

These lines from the previous example show the padding columns in the XAML that defines the title bar. Using padding columns instead of margins ensures that the background paints the area under the caption control buttons (for transparent buttons). Using both right and left padding columns ensures that your championship bar behaves correctly in both right-to-left and left-to-correct layouts.

                  <Grid.ColumnDefinitions>     <ColumnDefinition 10:Name="LeftPaddingColumn" Width="0"/>     <ColumnDefinition/>     <ColumnDefinition x:Proper noun="RightPaddingColumn" Width="0"/> </Grid.ColumnDefinitions>                                  

The dimensions and position of the caption command area is communicated by the AppWindowTitleBar class and so that yous tin account for it in the layout of your title bar UI. The width of the reserved region on each side is given past the LeftInset or RightInset properties, and its height is given by the Height property.

Here'southward how the width of the padding columns is specified when the elevate regions are calculated and set.

                  // Get caption button apoplexy data. int CaptionButtonOcclusionWidthRight = appWindow.TitleBar.RightInset; int CaptionButtonOcclusionWidthLeft = appWindow.TitleBar.LeftInset;  // Set the width of padding columns in the UI. RightPaddingColumn.Width = new GridLength(CaptionButtonOcclusionWidthRight); LeftPaddingColumn.Width = new GridLength(CaptionButtonOcclusionWidthLeft);                                  

Important

See important information in the Interactive content department about how display scaling affects these values.

Color and transparency in caption buttons

When you extend your app content into the title bar surface area, you lot tin make the background of the explanation buttons transparent to let your app groundwork evidence through. You lot typically set the background to Colors.Transparent for full transparency. For partial transparency, set the alpha aqueduct for the Color you set the property to.

  • Windows App SDK
  • WinUI 3
  • UWP/WinUI 2

(Windows eleven only. Come across Platform options for more info.)

These title bar properties tin be transparent:

  • ButtonBackgroundColor
  • ButtonHoverBackgroundColor
  • ButtonPressedBackgroundColor
  • ButtonInactiveBackgroundColor

All other color properties volition continue to ignore the blastoff channel. If ExtendsContentIntoTitleBar is set to false, the alpha channel is always ignored for all AppWindowTitleBar color properties.

Reference: Colors.Transparent, ColorHelper

The button background colour is not practical to the Close push hover and pressed states. The shut button always uses the system-defined color for those states.

Tip

Mica is a delightful material that helps distinguish the window that's in focus. We recommend information technology equally the groundwork for long-lived windows in Windows 11. If you lot have practical Mica in the customer area of your window, you can extend it into the titlebar surface area and make your caption buttons transparent for the Mica to testify through. Run across Mica fabric for more than info.

Dim the title bar when the window is inactive

You should brand it obvious when your window is active or inactive. At a minimum, you should change the color of the text, icons, and buttons in your title bar.

  • Windows App SDK
  • WinUI 3
  • UWP/WinUI ii

Handle an event to decide the activation land of the window, and update your title bar UI as needed. How you determine the state of the window depends on the UI framework y'all use for your app.

  • Win32: Listen and respond to the WM_ACTIVATE message.
  • WPF: Handle Window.Activated, Window.Deactivated.
  • WinForms: Handle Form.Activated, Grade.Deactivate.
  • WinUI three with Windows App SDK title bar APIs: Handle Window.Activated (See the WinUI 3 tab).

Reset the title bar

  • Windows App SDK
  • WinUI three
  • UWP/WinUI 2

(Windows 11 only. See Platform options for more info.)

To reset or switch to the system title bar while your app is running, you tin telephone call AppWindowTitleBar.ResetToDefault.

                  m_AppWindow.TitleBar.ResetToDefault();                                  

Show and hide the title bar

If yous add support for full screen or compact overlay modes to your app, you might need to make changes to your title bar when your app switches between these modes.

  • Windows App SDK
  • WinUI three
  • UWP/WinUI 2

(Windows 11 just. Meet Platform options for more than info.)

When your app runs in full screen way, the system hides the title bar and explanation control buttons. You tin handle the AppWindow.Inverse event and check the upshot args DidPresenterChange belongings to determine if you should prove, hibernate, or modify the title bar in response to a new window presentation.

This example shows how to handle the Changed event to testify and hide the AppTitleBar chemical element from previous examples. If the window is put in compact overlay mode, the title bar is reset to the default system title bar (or you lot could provide a custom title bar optimized for meaty overlay).

                  public MainWindow() {     this.InitializeComponent();      m_AppWindow = GetAppWindowForCurrentWindow();     m_AppWindow.Changed += AppWindow_Changed; }  private void AppWindow_Changed(AppWindow sender, AppWindowChangedEventArgs args) {     // Check to see if customization is supported.     // Currently but supported on Windows 11.     if (args.DidPresenterChange         && AppWindowTitleBar.IsCustomizationSupported())     {         switch (sender.Presenter.Kind)         {             case AppWindowPresenterKind.CompactOverlay:                 // Compact overlay - hide custom title bar                 // and use the default system title bar instead.                 AppTitleBar.Visibility = Visibility.Collapsed;                 sender.TitleBar.ResetToDefault();                 break;              example AppWindowPresenterKind.FullScreen:                 // Full screen - hide the custom title bar                 // and the default system championship bar.                 AppTitleBar.Visibility = Visibility.Complanate;                 sender.TitleBar.ExtendsContentIntoTitleBar = truthful;                 break;              case AppWindowPresenterKind.Overlapped:                 // Normal - hide the system title bar                 // and utilise the custom title bar instead.                 AppTitleBar.Visibility = Visibility.Visible;                 sender.TitleBar.ExtendsContentIntoTitleBar = true;                 SetDragRegionForCustomTitleBar(sender);                 break;              default:                 // Apply the default organisation title bar.                 sender.TitleBar.ResetToDefault();                 pause;         }     } }                                  

Exercise's and don'ts

  • Do make it obvious when your window is active or inactive. At a minimum, change the colour of the text, icons, and buttons in your championship bar.
  • Exercise define a drag region forth the peak border of the app canvass. Matching the placement of system championship bars makes information technology easier for users to find.
  • Do define a drag region that matches the visual title bar (if whatever) on the app's canvas.

Full customization example

This examples shows all the lawmaking described in the Full customization section.

  • Windows App SDK
  • WinUI 3
  • UWP/WinUI 2

(Windows 11 only. See Platform options for more info.)

                  <Window     x:Class="WASDK_ExtendedTitleBar.MainWindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:local="using:WASDK_ExtendedTitleBar"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     mc:Ignorable="d">      <Filigree>         <Grid.RowDefinitions>             <RowDefinition Tiptop="Automobile"/>             <RowDefinition />         </Grid.RowDefinitions>         <Filigree x:Proper name="AppTitleBar"         Height="48">             <Filigree.ColumnDefinitions>                 <ColumnDefinition x:Name="LeftPaddingColumn" Width="0"/>                 <ColumnDefinition x:Name="IconColumn" Width="Car"/>                 <ColumnDefinition 10:Name="TitleColumn" Width="Auto"/>                 <ColumnDefinition x:Name="LeftDragColumn" Width="*"/>                 <ColumnDefinition ten:Name="SearchColumn" Width="Auto"/>                 <ColumnDefinition x:Name="RightDragColumn" Width="*"/>                 <ColumnDefinition x:Proper name="RightPaddingColumn" Width="0"/>             </Grid.ColumnDefinitions>             <Image 10:Proper noun="TitleBarIcon" Source="/Images/WindowIcon.png"            Grid.Column="one"            Width="16" Height="16"            Margin="8,0,0,0"/>             <TextBlock x:Name="TitleTextBlock"                 Text="App title"                 Manner="{StaticResource CaptionTextBlockStyle}"                Grid.Column="two"                VerticalAlignment="Center"                Margin="iv,0,0,0"/>             <AutoSuggestBox Grid.Column="4" QueryIcon="Find"                     PlaceholderText="Search"                     VerticalAlignment="Centre"                     Width="260" Margin="iv,0"/>         </Grid>          <NavigationView Filigree.Row="i"                         IsBackButtonVisible="Collapsed"                          IsSettingsVisible="False">             <StackPanel>                 <TextBlock Text="Content"                             Way="{ThemeResource TitleTextBlockStyle}"                            Margin="32,0,0,0"/>                 <StackPanel Grid.Row="1" VerticalAlignment="Center">                     <Button Margin="four" x:Name="CompactoverlaytBtn"                             Content="Enter CompactOverlay"                             Click="SwitchPresenter"/>                     <Button Margin="iv" x:Name="FullscreenBtn"                              Content="Enter FullScreen"                             Click="SwitchPresenter"/>                     <Push button Margin="4" x:Name="OverlappedBtn"                             Content="Revert to default (Overlapped)"                             Click="SwitchPresenter"/>                 </StackPanel>             </StackPanel>         </NavigationView>     </Filigree> </Window>                                  
                  using Microsoft.UI; using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Organization; using Organisation.Collections.Generic; using System.Runtime.InteropServices; using WinRT.Interop;  namespace WASDK_ExtendedTitleBar {     public sealed partial course MainWindow : Window     {         private AppWindow m_AppWindow;          public MainWindow()         {             this.InitializeComponent();              m_AppWindow = GetAppWindowForCurrentWindow();             m_AppWindow.Changed += AppWindow_Changed;              // Check to run across if customization is supported.             // Currently only supported on Windows 11.             if (AppWindowTitleBar.IsCustomizationSupported())             {                 var titleBar = m_AppWindow.TitleBar;                 titleBar.ExtendsContentIntoTitleBar = true;                 AppTitleBar.Loaded += AppTitleBar_Loaded;                 AppTitleBar.SizeChanged += AppTitleBar_SizeChanged;             }             else             {                 // Championship bar customization using these APIs is currently                 // supported only on Windows xi. In other cases, hide                 // the custom championship bar element.                 AppTitleBar.Visibility = Visibility.Collapsed;                  // Prove alternative UI for any functionality in                 // the title bar, such as search.             }          }          private void AppTitleBar_Loaded(object sender, RoutedEventArgs eastward)         {             if (AppWindowTitleBar.IsCustomizationSupported())             {                 SetDragRegionForCustomTitleBar(m_AppWindow);             }         }          private void AppTitleBar_SizeChanged(object sender, SizeChangedEventArgs e)         {             if (AppWindowTitleBar.IsCustomizationSupported()                 && m_AppWindow.TitleBar.ExtendsContentIntoTitleBar)             {                 // Update elevate region if the size of the title bar changes.                 SetDragRegionForCustomTitleBar(m_AppWindow);             }         }          individual AppWindow GetAppWindowForCurrentWindow()         {             IntPtr hWnd = WindowNative.GetWindowHandle(this);             WindowId wndId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);             return AppWindow.GetFromWindowId(wndId);         }          [DllImport("Shcore.dll", SetLastError = truthful)]         internal static extern int GetDpiForMonitor(IntPtr hmonitor, Monitor_DPI_Type dpiType, out uint dpiX, out uint dpiY);          internal enum Monitor_DPI_Type : int         {             MDT_Effective_DPI = 0,             MDT_Angular_DPI = 1,             MDT_Raw_DPI = 2,             MDT_Default = MDT_Effective_DPI         }          private double GetScaleAdjustment()         {             IntPtr hWnd = WindowNative.GetWindowHandle(this);             WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);             DisplayArea displayArea = DisplayArea.GetFromWindowId(wndId, DisplayAreaFallback.Master);             IntPtr hMonitor = Win32Interop.GetMonitorFromDisplayId(displayArea.DisplayId);              // Go DPI.             int result = GetDpiForMonitor(hMonitor, Monitor_DPI_Type.MDT_Default, out uint dpiX, out uint _);             if (result != 0)             {                 throw new Exception("Could not get DPI for monitor.");             }              uint scaleFactorPercent = (uint)(((long)dpiX * 100 + (96 >> 1)) / 96);             render scaleFactorPercent / 100.0;         }          private void SetDragRegionForCustomTitleBar(AppWindow appWindow)         {             if (AppWindowTitleBar.IsCustomizationSupported()                 && appWindow.TitleBar.ExtendsContentIntoTitleBar)             {                 double scaleAdjustment = GetScaleAdjustment();                  RightPaddingColumn.Width = new GridLength(appWindow.TitleBar.RightInset / scaleAdjustment);                 LeftPaddingColumn.Width = new GridLength(appWindow.TitleBar.LeftInset / scaleAdjustment);                  List<Windows.Graphics.RectInt32> dragRectsList = new();                  Windows.Graphics.RectInt32 dragRectL;                 dragRectL.X = (int)((LeftPaddingColumn.ActualWidth) * scaleAdjustment);                 dragRectL.Y = 0;                 dragRectL.Summit = (int)(AppTitleBar.ActualHeight * scaleAdjustment);                 dragRectL.Width = (int)((IconColumn.ActualWidth                                         + TitleColumn.ActualWidth                                         + LeftDragColumn.ActualWidth) * scaleAdjustment);                 dragRectsList.Add together(dragRectL);                  Windows.Graphics.RectInt32 dragRectR;                 dragRectR.X = (int)((LeftPaddingColumn.ActualWidth                                     + IconColumn.ActualWidth                                     + TitleTextBlock.ActualWidth                                     + LeftDragColumn.ActualWidth                                     + SearchColumn.ActualWidth) * scaleAdjustment);                 dragRectR.Y = 0;                 dragRectR.Pinnacle = (int)(AppTitleBar.ActualHeight * scaleAdjustment);                 dragRectR.Width = (int)(RightDragColumn.ActualWidth * scaleAdjustment);                 dragRectsList.Add(dragRectR);                  Windows.Graphics.RectInt32[] dragRects = dragRectsList.ToArray();                  appWindow.TitleBar.SetDragRectangles(dragRects);             }         }          private void AppWindow_Changed(AppWindow sender, AppWindowChangedEventArgs args)         {             if (args.DidPresenterChange                 && AppWindowTitleBar.IsCustomizationSupported())             {                 switch (sender.Presenter.Kind)                 {                     case AppWindowPresenterKind.CompactOverlay:                         // Meaty overlay - hide custom championship bar                         // and use the default system title bar instead.                         AppTitleBar.Visibility = Visibility.Collapsed;                         sender.TitleBar.ResetToDefault();                         break;                      case AppWindowPresenterKind.FullScreen:                         // Full screen - hide the custom title bar                         // and the default arrangement title bar.                         AppTitleBar.Visibility = Visibility.Collapsed;                         sender.TitleBar.ExtendsContentIntoTitleBar = truthful;                         intermission;                      case AppWindowPresenterKind.Overlapped:                         // Normal - hide the organisation championship bar                         // and utilise the custom title bar instead.                         AppTitleBar.Visibility = Visibility.Visible;                         sender.TitleBar.ExtendsContentIntoTitleBar = true;                         SetDragRegionForCustomTitleBar(sender);                         intermission;                      default:                         // Utilize the default system title bar.                         sender.TitleBar.ResetToDefault();                         break;                 }             }         }          individual void SwitchPresenter(object sender, RoutedEventArgs east)         {             if (m_AppWindow != null)             {                 AppWindowPresenterKind newPresenterKind;                 switch ((sender as Button).Name)                 {                     example "CompactoverlaytBtn":                         newPresenterKind = AppWindowPresenterKind.CompactOverlay;                         break;                      case "FullscreenBtn":                         newPresenterKind = AppWindowPresenterKind.FullScreen;                         suspension;                      example "OverlappedBtn":                         newPresenterKind = AppWindowPresenterKind.Overlapped;                         intermission;                      default:                         newPresenterKind = AppWindowPresenterKind.Default;                         break;                 }                  // If the aforementioned presenter button was pressed as the                 // manner we're in, toggle the window dorsum to Default.                 if (newPresenterKind == m_AppWindow.Presenter.Kind)                 {                     m_AppWindow.SetPresenter(AppWindowPresenterKind.Default);                 }                 else                 {                     // Else asking a presenter of the selected kind                     // to be created and applied to the window.                     m_AppWindow.SetPresenter(newPresenterKind);                 }             }         }     } }                                  
  • Acrylic
  • Mica
  • Color