dotMorten / WinUIEx

WinUI Extensions
https://dotmorten.github.io/WinUIEx
MIT License
572 stars 36 forks source link

Changing TitleBar BackgroundColor In MAUI has no affect. #163

Closed malsabi closed 4 months ago

malsabi commented 4 months ago

Description

I am experiencing an issue with a .NET MAUI application where the background color of the title bar is not changing as expected. I am using the following code in my MauiAppBuilder configuration to set the title bar's background color to red, but the color does not change when the application is run.

Code Snippet


private static void ConfigureWindowsLifecycleEvents(MauiAppBuilder builder)
{
    builder.ConfigureLifecycleEvents(events =>
    {
        events.AddWindows(wndLifeCycleBuilder =>
        {
            wndLifeCycleBuilder.OnWindowCreated(window =>
            {
                WindowManager manager = WindowManager.Get(window);
                manager.MinWidth = 800;
                manager.MinHeight = 800;
                manager.WindowState = WindowState.Maximized;
                manager.AppWindow.TitleBar.BackgroundColor = Microsoft.UI.Colors.Red;
            });
        });
    });
}
dotMorten commented 4 months ago

AppWindow.Titlebar isn't a WinUIEx API but a Windows App SDK API. You could just use window.AppWindow instead of getting to it via the WindowManager to access the same thing and not use any WinUIEx APIs at all. Also note that the titlebar customizations are not supported on Windows 10: https://learn.microsoft.com/en-us/windows/apps/develop/title-bar#colors