microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.3k stars 675 forks source link

New TitleBar Caption Button Colors does not work properly #9788

Open ghost1372 opened 2 months ago

ghost1372 commented 2 months ago

Describe the bug

New TitleBar Caption Button Colors only works when Windows Theme and App Theme is Same! for example: Windows Theme: Dark App Theme: Dark Caption Button Colors is Correct.

image

Windows Theme: Dark App Theme: Light Caption Button Colors is Wrong. image

and vice verca:

Windows Theme: Light App Theme: Light Caption Button Colors is Correct image

Windows Theme: Light App Theme: Dark Caption Button Colors is Wrong image

Steps to reproduce the bug

1.Create new titlebar app 2.Set Windows Theme to Dark 3.Set App Theme to Light

  1. See Wrong Colors

or

Set Windows Theme to Light Set App Theme to Dark See Wrong Colors

Expected behavior

No response

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.6 Experimental 2: 1.6.240701003-experimental2

Windows version

Windows 11 (22H2): Build 22621

Additional context

No response

github-actions[bot] commented 2 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Open similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

ghost1372 commented 2 months ago

@ranjeshj we can fix issue with this:

private void AppTitleBar_Loaded(object sender, RoutedEventArgs e)
{
    ApplySystemThemeToCaptionButtons(this);
}

private void AppTitleBar_ActualThemeChanged(FrameworkElement sender, object args)
{
    ApplySystemThemeToCaptionButtons(this);
}
public static void ApplySystemThemeToCaptionButtons(Window window)
{
    var res = Application.Current.Resources;
    Windows.UI.Color buttonForegroundColor;
    Windows.UI.Color buttonHoverForegroundColor;

    Windows.UI.Color buttonHoverBackgroundColor;
    if (App.themeService?.ActualTheme == ElementTheme.Dark)
    {
        buttonForegroundColor = WinUICommunity.ColorHelper.GetColorFromHex("#FFFFFF");
        buttonHoverForegroundColor = WinUICommunity.ColorHelper.GetColorFromHex("#FFFFFF");

        buttonHoverBackgroundColor = WinUICommunity.ColorHelper.GetColorFromHex("#0FFFFFFF");
    }
    else
    {
        buttonForegroundColor = WinUICommunity.ColorHelper.GetColorFromHex("#191919");
        buttonHoverForegroundColor = WinUICommunity.ColorHelper.GetColorFromHex("#191919");

        buttonHoverBackgroundColor = WinUICommunity.ColorHelper.GetColorFromHex("#09000000");
    }
    res["WindowCaptionForeground"] = buttonForegroundColor;

    window.AppWindow.TitleBar.ButtonForegroundColor = buttonForegroundColor;
    window.AppWindow.TitleBar.ButtonHoverForegroundColor = buttonHoverForegroundColor;

    window.AppWindow.TitleBar.ButtonHoverBackgroundColor = buttonHoverBackgroundColor;
}