Windows Title Bar in .NET MAUI (Win UI 3)

J0nathan550 20 Reputation points
2023-11-16T14:51:31.3433333+00:00

Hello, I have a question that I always wanted to ask related to Windows Title bar (i'm talking about this one):User's image

When .NET 8 released, I saw that it switched the WinUI to 3 version, which support Title Bar customization.

My question is how to modify this Title Bar?

How to change the color of title bar (to no be accent from user for example I want this title bar to be black.)

How to add icon?

How to add additional items like in other Win11 apps?User's image

How with WinUI 3 assign to your visual Myca style or Acryl?

I hope I will get answer onto how modify title bar since this is only topic that bothers me.

Developer technologies | .NET | .NET MAUI
Windows for business | Windows Client for IT Pros | User experience | Other
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-11-17T06:00:10.41+00:00

    Hello,

    Avoid posting multiple questions in a single thread in Q&A

    Let's focus on the first issue, you can open new threads for other issues.

    How to change the color of title bar (to no be accent from user for example I want this title bar to be black.)

    You can get the titlebar in the following ConfigureLifecycleEvents, then set the background color to black for titlebar, three button's background and the inactive status.

        public static class MauiProgram
        {
            public static MauiApp CreateMauiApp()
            {
                var builder = MauiApp.CreateBuilder();
                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.BackgroundColor = Colors.Black.ToWindowsColor();
                                          titleBar.ButtonBackgroundColor = Colors.Black.ToWindowsColor();                                             
                                          titleBar.InactiveBackgroundColor = Colors.Black.ToWindowsColor();    
                                          titleBar.ButtonInactiveBackgroundColor = Colors.Black.ToWindowsColor();
    
    
                                      });
    #endif
                                  });
                              })
    

    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.