VsixCommunity / Community.VisualStudio.Toolkit

Making it easier to write Visual Studio extensions
Other
253 stars 44 forks source link

Resolve correct System Default Theme #394

Open niemyjski opened 1 year ago

niemyjski commented 1 year ago

In visual studio there is the option for the theme to track the system default theme which returns a guid of {619dac1e-8220-4bd9-96fb-75ceb61a6107} This is not accounted for here: https://github.com/VsixCommunity/Community.VisualStudio.Toolkit/blob/master/demo/VSSDK.TestExtension/ToolWindows/ThemeWindow/ThemeWindowControlViewModel.cs#L21-L44 What's the best solution to resolve light or dark theme based on this?

reduckted commented 1 year ago

You'll probably need to ask Windows what the system theme is. This StackOverflow question has some suitable solutions.

This one checks the value of the registry key (0 = dark; 1 = light).

This one is a bit of a hack, but I've confirmed that it works. It uses the Microsoft.Windows.SDK.Contracts package to get the color values for the foreground and background and uses them to determine whether the theme is dark or light.

niemyjski commented 1 year ago

Thanks for that, shouldn't this library also resolve this properly as without it you won't get the correct theme and this theme is the default for VS