Can I make a fully custom title bar

CodeIsUnexecutable 0 Reputation points

Is there a way to hide the default title bar and make my own? I can't seem to find a way to make one that could move the window around.

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,049 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 70,556 Reputation points Microsoft Vendor


    Is there a way to hide the default title bar and make my own?

    Yes, you can do this by SetBorderAndTitleBar

    SetBorderAndTitleBar(Boolean, Boolean) Sets the border and title bar properties of the window.

    Before you set it, you need to get AppWindow, you can get it and hide titlebar by following code in the MauiProgram.cs.

    #if WINDOWS
                builder.ConfigureLifecycleEvents(events =>
                    events.AddWindows(wndLifeCycleBuilder =>
                        wndLifeCycleBuilder.OnWindowCreated(window =>
                            window.ExtendsContentIntoTitleBar = false;
                            /*prevent your app content extends into the title bar area.*/
                            IntPtr nativeWindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
                            Microsoft.UI.WindowId win32WindowsId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(nativeWindowHandle);
                            Microsoft.UI.Windowing.AppWindow winuiAppWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(win32WindowsId);
                            if (winuiAppWindow.Presenter is Microsoft.UI.Windowing.OverlappedPresenter p)
                                p.SetBorderAndTitleBar(false, false);

    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 comments No comments