diff --git a/docs/user-interface/controls/titlebar/titlebar.md b/docs/user-interface/controls/titlebar/titlebar.md index 26bdd86c0..4f78bc64a 100644 --- a/docs/user-interface/controls/titlebar/titlebar.md +++ b/docs/user-interface/controls/titlebar/titlebar.md @@ -1,6 +1,13 @@ -# Customize the Title bar +--- +title: Customize the title bar +description: How to use and customize the .NET MAUI title bar control +author: Foda +ms.date: 10/15/2024 +--- -The `TitleBar` control makes it easy to create a great, customizable titlebar for your app with the following features: +# Customize the title bar + +The control makes it easy to create a customizable titlebar for your MAUI app with the following features: * Configurable Icon, Title, and Subtitle properties * Integrated shell buttons @@ -11,11 +18,11 @@ The `TitleBar` control makes it easy to create a great, customizable titlebar fo ![Title bar component overview](media/overview.png) -## Create a default Window +## Create a default window -To customize the title bar in your application, you can simply add a `TitleBar` control to a parent `Window` object. However, .NET MAUI automatically handles the creation of the `Window` object, so we must first override how a new `Window` is created. +To customize the title bar in your application, you can simply add a control to a parent object. However, .NET MAUI automatically handles the creation of the `Window` object, so we must first override how a new `Window` is created. -First, create a new file named `MainWindow.xaml`: +First, create a new file named _MainWindow.xaml_, which will inherit from the default `Window` class: ```xml ``` -Then, modify `MainWindow.xaml.cs`: +Then, modify _MainWindow.xaml.cs_: ```csharp namespace TitlebarSample; @@ -39,7 +46,7 @@ public partial class MainWindow : Window } ``` -Finally, modify `App.xaml.cs` to use the new `MainWindow` object: +Finally, modify _App.xaml.cs_ to return the newly created `MainWindow` object: ```csharp public partial class App : Application { @@ -57,7 +64,7 @@ public partial class App : Application ## Add a new title bar control -Next, set the `Window.TitleBar` property to the `TitleBar` control: +Next, set the property to the `TitleBar` control: ```xml , , and properties to display interactive controls in the title bar. Any content set in these properties will automatically recieve input while blocking the title bar drag behavior. You can also set the height of the title bar to fit the added content. -For example, to add a search box and settings button you can utilize the `Content` and `TrailingContent` properties: +For example, to add a search box and settings button you can utilize the and properties: ![Title bar with search box](media/sample_3.png) ```xml @@ -114,13 +121,14 @@ For example, to add a search box and settings button you can utilize the `Conten ``` + ## Match title bar and menu bar background color -When using `MenuBarItems` you may want to match the title bar menu bar items background color: +When using you may want to match the title bar and menu bar background color: ![Title bar with menu bar items](media/sample_2.png) -To do this, modify the `NavigationPage.BarBackgroundColor` property to match the color of the title bar: +To do this, modify the property to match the color of the title bar: ```csharp public partial class App : Application @@ -142,7 +150,7 @@ public partial class App : Application ## Override the default template -If the default components on the `TitleBar` control do not meet your needs, you can also override the default control template to fully customize the title bar: +If the default components on the `TitleBar` control do not meet your needs, you can also override the default control template to fully customize the title bar behavior: ```xml @@ -168,11 +176,11 @@ If the default components on the `TitleBar` control do not meet your needs, you ``` > [!NOTE] -> When overriding the default control template, you must add the interactive elements to the `TitleBar.PassthroughElements` property otherwise they will not recieve input. +> When overriding the default control template, you must add the interactive elements to the property otherwise they will not recieve input. ### Title bar visual states -`TitleBar` objects have `TitleBarTitleActive` and `TitleBarTitleInactive` states to indicate when the window is active or inactive. +The `TitleBar` control has the `TitleBarTitleActive` and `TitleBarTitleInactive` states to indicate when the parent window is active or inactive. The following XAML example shows how to define a visual state for the `TitleBarTitleActive` and `TitleBarTitleInactive` states: @@ -199,4 +207,4 @@ The following XAML example shows how to define a visual state for the `TitleBarT -``` \ No newline at end of file +```