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.