[UWP] [C++] How do I set theme as system default?

Eric Tian 211 Reputation points
2020-08-29T22:39:43.82+00:00

Hello,

I'm trying to create an app setting in c++ uwp and it has three radio buttons: "Light" "Dark" and "System Default". How do get the system default (light, dark, etc.) when I initialize the app? Thank you.

Universal Windows Platform (UWP)
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
2,633 questions
No comments
{count} votes

Accepted answer
  1. Eric Tian 211 Reputation points
    2020-08-30T18:56:47.287+00:00

    Save "System Theme" to app data and on app initialization, do this:

    auto DefaultTheme = ref new Windows::UI::ViewManagement::UISettings();
    auto uiTheme = DefaultTheme->GetColorValue(Windows::UI::ViewManagement::UIColorType::Background).ToString();
    if (uiTheme == "#FF000000")
    {
        App::Current->RequestedTheme = ApplicationTheme::Dark;
    }
    else if (uiTheme == "#FFFFFFFF")
    {
        App::Current->RequestedTheme = ApplicationTheme::Light;
    }
    

0 additional answers

Sort by: Most helpful