Rhemsuda
Rhemsuda
CC#
Created by Rhemsuda on 12/29/2023 in #help
Maui TitleBar transparency & changing Caption Control colors?
Hey folks, I'm having a hell of a time updating the Windows Titlebar using Maui and Windows API. I've tried probably everything I can think of but this is just a massive game of whack-a-mole. I have this code that I've been able to use to get rid of the titlebar, allow the background and contents to extend into the titlebar, however I cannot for the life of me change the colors of the Background. I cannot use the AppWindow.TitleBar colors as when I do this, I'm unable to change the transparency of the titlebar, and when I set ExtendsContentIntoTitleBar to false, I get two title bars layered on top of one another (wut?). So the closest I've been able to get is to remove the titlebar using the OverlappedPresenter and set the titlebar to some blank grid to get rid of the extra space on the side. My code is as follows:
builder.ConfigureLifecycleEvents(events =>
{
events.AddWindows(wndLifeCycleBuilder =>
{
wndLifeCycleBuilder.OnWindowCreated(window =>
{
window.ExtendsContentIntoTitleBar = true;
IntPtr nativeWindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
WindowId win32WindowsId = Win32Interop.GetWindowIdFromWindow(nativeWindowHandle);
AppWindow winuiAppWindow = AppWindow.GetFromWindowId(win32WindowsId);

if (winuiAppWindow.Presenter is OverlappedPresenter p)
{
p.SetBorderAndTitleBar(false, false);
}

window.SetTitleBar(new Microsoft.UI.Xaml.Controls.Grid());
});
});
});
builder.ConfigureLifecycleEvents(events =>
{
events.AddWindows(wndLifeCycleBuilder =>
{
wndLifeCycleBuilder.OnWindowCreated(window =>
{
window.ExtendsContentIntoTitleBar = true;
IntPtr nativeWindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
WindowId win32WindowsId = Win32Interop.GetWindowIdFromWindow(nativeWindowHandle);
AppWindow winuiAppWindow = AppWindow.GetFromWindowId(win32WindowsId);

if (winuiAppWindow.Presenter is OverlappedPresenter p)
{
p.SetBorderAndTitleBar(false, false);
}

window.SetTitleBar(new Microsoft.UI.Xaml.Controls.Grid());
});
});
});
My title bar currently looks like image 1, where I need it to look like image 2.
1 replies