Can I make a fully custom title bar

CodeIsUnexecutable 0 Reputation points
2023-10-24T16:46:58.37+00:00

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.

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-10-25T06:26:31.3566667+00:00

    Hello,

    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);
                            }
                           
                        });
                    });
                });
    #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 comments No comments

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.