Get the Windows 10 theme

-2

Good morning.

My question is if there is any way to get in C # if the system is in dark / light mode / theme and make the requested theme of the app be the same.

The configuration of the theme in Windows is this:

For example, if I have a background grid, when the computer is set to dark mode, that grid will turn black. I know that by putting the following the emphasis color is achieved:

Grid.Background = new SolidColorBrush((Color)Resources["SystemAccentColor"]);

But what I need is the light or dark theme defined by the user in the Windows configuration.

Thanks for everything!

    
asked by MTKt 22.07.2017 в 18:51
source

1 answer

2

This solution works from the Aniversary Update

Go to the file App.xaml and remove the following line:

<Application
    ...
    RequestedTheme="Light">
</Application>

Then this is you can access the Windows theme by:

Application.Current.RequestedTheme

However, it may not be necessary to find the current topic anymore because the app will also use the Windows theme.

If you do not remove the line from App.xaml the ApplicationTheme returned by the call to the previous method will always be the one defined in App.xaml

    
answered by 25.07.2017 в 16:30