WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

Apps use the wrong theme for the system context menu

Open Balkoth opened this issue 2 years ago • 3 comments

Describe the bug

Apps on a system that is configured to use the dark theme use the light system context menu theme:

Context menu looks like this: image

When it should look like this: image

Steps to reproduce the bug

Create a new project on a system that is configured to use dark mode.

Expected behavior

No response

Screenshots

No response

NuGet package version

1.1.4

Packaging type

Packaged (MSIX), Unpackaged

Windows version

Windows 10 version 21H2 (19044, November 2021 Update)

IDE

Visual Studio 2022

Additional context

The right theme for the context menue is chosen when you call into an undocumented function in uxtheme.dll:

[DllImport("uxtheme.dll", EntryPoint = "#135", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern int SetPreferredAppMode(int preferredAppMode);

According to this there are a number of values for the int parameter.

Call this function on program start to choose the right mode for the current configuration.

Balkoth avatar Sep 07 '22 11:09 Balkoth

It works fine for me (Windows 10 21H1, Windows app SDK 1.1.0) : SetPreferredAppMode

castorix avatar Sep 07 '22 19:09 castorix

The bug is also present in 1.1.5 for me.

@castorix I think you got wrong what i said. If i use SetPreferredAppMode this of course works. But i should not have to use an undocumented function, this should work out of the box.

Balkoth avatar Sep 15 '22 09:09 Balkoth

The bug is also present in 1.1.5 for me.

@castorix I think you got wrong what i said. If i use SetPreferredAppMode this of course works. But i should not have to use an undocumented function, this should work out of the box.

Ah ok. I thought it did not work on Windows 10 21H2 Indeed, we should not have to call undocumented APIs for this

castorix avatar Sep 15 '22 10:09 castorix

This is not a bug per se, it is how win32 works today - if you just create a window in a "blank app" in win32 you will get the light theme system menu, this is the same for a WinUI WinAppSDK app.

I do however agree that this does not look good, and at least WinAppSDK apps should properly handle light/dark mode out of the box with no need for developers to do anything special. @MikeHillberg @ryandemopoulos - I think this (theme/mode aware) is something that needs a broader support/investment across components of WinAppSDK.

With that in mind, I'd like to see this converted from a bug into a feature suggestion.

rkarman avatar Oct 06 '22 20:10 rkarman

Windows explorer says otherwise, it switches to the correct menu theme upon changing from light to dark. Every app that does not reflect this looks buggy to me, so i consider this to be a bug.

Balkoth avatar Oct 06 '22 21:10 Balkoth

Related: #41

sylveon avatar Jan 05 '23 23:01 sylveon

Since I'm no longer PM:ing this area I'm unassigning me. @MikeHillberg and @ryandemopoulos (who've been assigned for a while as well) will continue to drive this topic.

rkarman avatar Feb 13 '23 23:02 rkarman