Home > OS >  How do I customize the app bar in Maui applications?
How do I customize the app bar in Maui applications?

Time:12-26

I am new to Desktop Development on the .net MAUI platform, I ran into a weird issue with customizing the app bar. I would like to change the app bar color and add content it but I have no idea how to.
enter image description here enter image description here

https://learn.microsoft.com/en-us/windows/apps/develop/title-bar?tabs=wasdk#platform-options

CodePudding user response:

I don't know if it is what you need but if you declared the menuitems in AppShell.xaml you can change there the background. Just do it in the cunstructor:

<AppShell 
[...]
Background="blue">
[...]
<AppShell>

If this is not what you mean specify your post and also add your code.

CodePudding user response:

Per How much to customize the title bar,there are two levels of customization that you can apply to the title bar: apply minor modifications to the default title bar, or extend your app canvas into the title bar area and provide completely custom content.

To change the color of the app title bar, you can try the code below:

#if WINDOWS
            var uiSettings = new Windows.UI.ViewManagement.UISettings();
            var color = uiSettings.GetColorValue(UIColorType.Accent);
            Microsoft.UI.Xaml.Window window = (Microsoft.UI.Xaml.Window)App.Current.Windows.First<Window>().Handler.PlatformView;
            //get the current window on the windows platform
            IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
            Microsoft.UI.WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
            Microsoft.UI.Windowing.AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
            Microsoft.UI.Windowing.AppWindowTitleBar titlebar = appWindow.TitleBar;
           //titlebar.ExtendsContentIntoTitleBar = true;
           //You may need to uncomment the line above
            titlebar.BackgroundColor = color;
#endif

To add content to the title bar, you could try to modify the App.xaml under the Windows project. For more details, you can refer to Fix AppTitleBarHeight to match caption button heights #5811

  • Related