Just a small tip for desktop UWP apps!

I needed to look this up and it took me more time than I thought it would… so blogging it for reference 🙂

If you create an UWP app, you’ll notice that the app title bar will change color depending on the fact it has or has not the focus.

This can be useful, but if you already themed your app and took time to style the titlebar with some color, it just looks weird the color is no longer the same when not in focus.

So what do you need to do to get the app title bar stay the same, here is the code:

if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView")) { var titleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar; if(titleBar != null) { titleBar.InactiveBackgroundColor = titleBar.BackgroundColor = titleBar.ButtonInactiveBackgroundColor = titleBar.ButtonBackgroundColor = (Color)App.Current.Resources["KlivaMainColor"]; titleBar.ForegroundColor = titleBar.ButtonForegroundColor = Windows.UI.Colors.White; } } 1 2 3 4 5 6 7 8 9 if ( ApiInformation . IsTypePresent ( "Windows.UI.ViewManagement.ApplicationView" ) ) { var titleBar = Windows . UI . ViewManagement . ApplicationView . GetForCurrentView ( ) . TitleBar ; if ( titleBar != null ) { titleBar . InactiveBackgroundColor = titleBar . BackgroundColor = titleBar . ButtonInactiveBackgroundColor = titleBar . ButtonBackgroundColor = ( Color ) App . Current . Resources [ "KlivaMainColor" ] ; titleBar . ForegroundColor = titleBar . ButtonForegroundColor = Windows . UI . Colors . White ; } }

You first check if we are running in desktop mode, if so we get a hold of the titlebar and when you have that, just set Inactive*** properties the same as the normal ones!

That’s it…

Happy coding