Hello,
If you use windows 11 and .NET 7, you can custom this titlebar's color by TitleBar's BackgroundColor property in the MauiPrograms.cs
As note:Color customization is ignored when the app runs on Windows 10.
builder
.UseMauiApp<App>()
.ConfigureLifecycleEvents(events =>
{
#if WINDOWS
events.AddWindows(windowsLifecycleBuilder =>
{
windowsLifecycleBuilder.OnWindowCreated(window =>
{
var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);
var id = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(handle);
var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(id);
var titleBar = appWindow.TitleBar;
titleBar.ForegroundColor = Colors.White.ToWindowsColor();
titleBar.BackgroundColor = Color.FromRgb(81, 43, 212).ToWindowsColor();
titleBar.ButtonBackgroundColor = Color.FromRgb(81, 43, 212).ToWindowsColor();
});
#endif
});
})
However, if you use .NET 8, titleBar.BackgroundColor
is not working, but other ButtonBackgroundColor is working as normal. Please report this issue in MAUI Github repo and share link here.
Here is another solution to change the titlebar's background color, it this working for .NET 8.
Please open the App.xaml
in the Platforms\Windows
folder, add following code in the <maui:MauiWinUIApplication>
tag, you can change the title bar's background color by Background
in Border
control, and you need to reset the title by TextBlock
control
<maui:MauiWinUIApplication.Resources>
<DataTemplate x:Key="MauiAppTitleBarTemplate">
<Grid >
<Border
Canvas.ZIndex="1"
VerticalAlignment="Stretch"
Background="Pink"
Margin="0,0,0,0">
<TextBlock
Foreground="Red"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Text="your application title"
FontWeight="Bold"/>
</Border>
</Grid>
</DataTemplate>
</maui:MauiWinUIApplication.Resources>
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.