Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
813 views
in Technique[技术] by (71.8m points)

uwp - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...