Search code examples
visual-studio-2022winui-3windows-11winuiwindows-app-sdk

Transparent title bar in WinUI 3 app (Windows 11)


I develop some UWP apps to Windows10 and I want put the tile bar transparent in a new app developed in WinUi3.

If I try this ExtendsContentIntoTitleBar = true; The minimize, maximize and close buttons disappear, and I cannot move the app in my Window.

But in UWP it was more simple. I can put the title bar transparent (or with the same color of my app) without any problem, something like this:

CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
titleBar.ButtonBackgroundColor = Colors.Transparent;
titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
titleBar.ButtonForegroundColor = Colors.Black;

It is possible something like that in WinUi3?


Solution

  • According to the Doc:

    If you set ExtendsContentIntoTitleBar to true but do not call SetTitleBar, the system title bar is restricted to the caption buttons and a small area next to the caption buttons that is reserved for title bar behaviors. However, your custom title bar element does not get title bar behaviors, such as drag and the system menu, until SetTitleBar is called with a valid UIElement.

    Set the transparency by setting the value of UIElement.Opacity Property:

    The value between 0 and 1.0 that declares the opacity factor, with 1.0 meaning full opacity and 0 meaning transparent. The default value is 1.0.