简体   繁体   中英

Retain custom titlebar color when not in focus

I have a UWP app with custom titlebar background & foreground color. It works great except when the app is not in focus it will turn the titlebar back to the original white color.

public MainPage()
    {
        this.InitializeComponent();

        Windows.UI.ViewManagement.ApplicationViewTitleBar titleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;
        titleBar.BackgroundColor = Windows.UI.Colors.Black;
        titleBar.ForegroundColor = Windows.UI.Colors.White;
        titleBar.ButtonBackgroundColor = Windows.UI.Colors.Black;
        titleBar.ButtonForegroundColor = Windows.UI.Colors.White;     
    }

How do I retain the custom titlebar color even when the app is not in focus?

There are Inactive colors for this purpose.

titleBar.InactiveBackgroundColor = titleBar.BackgroundColor = Windows.UI.Colors.Black;
titleBar.InactiveForegroundColor = titleBar.ForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonInactiveBackgroundColor = titleBar.ButtonBackgroundColor = Windows.UI.Colors.Black;
titleBar.ButtonInactiveForegroundColor = titleBar.ButtonForegroundColor = Windows.UI.Colors.White;

The Buttons have Hover and Pressed color sets too.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM