Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect Windows 10 light/dark mode?

I'm using Windows.UI.ViewManagement.UISettings to get system accent color but it seems this class does not have any method or property for light/dark mode. I failed to find a document for this feature, how can I detect this?

PS: I'm making a JS app which does not have access for Windows.UI.Xaml namespace.

like image 554
Kagami Sascha Rosylight Avatar asked Aug 03 '16 04:08

Kagami Sascha Rosylight


People also ask

Does Windows 10 have Light and dark mode?

To enable dark mode, navigate to Settings > Personalization > Colors, then open the drop-down menu for "Choose your color" and pick Dark. Dark (and Light) mode change the look of the Windows Start menu and built-in apps. You can also decide to choose Custom if you want to mix and match color themes.

Is my computer in dark mode?

Select Start > Settings . Select Personalization > Colors. Under Choose your color, select Custom. Under Choose your default Windows mode, select Dark.

How do I get rid of Windows 10 dark mode?

Click on Start > Cogwheel icon > Settings. Step 3: As you hit the Personalization option, a panel will open up on the left side of your computer screen. Click the “Colors” option. You will see three options: “Choose your color,” “Choose your default Window mode,” and “Choose your default app mode”.


1 Answers

You can create a Windows Runtime Component project in your solution from there you access Windows.UI.Xaml namespace. Add a method to check current ApplicationTheme like that.

public sealed class Test
{
    public static string CurrentTheme()
    {
        var isDark = Application.Current.RequestedTheme == ApplicationTheme.Dark;

        if (isDark)
            return "Dark";

        return "Light";
    }
}

Add reference to windows runtime component project in your javascript app project and you can call this method where ever you want to check application theme. Take a look here for walkthrough on createing Windows Runtime Component.

like image 189
Aman Sharma Avatar answered Sep 24 '22 18:09

Aman Sharma