2

how to get windows system theme in UWP? Light/Dark

var DefaultTheme = new Windows.UI.ViewManagement.UISettings();
WindowsThemeText.Text =DefaultTheme.UIElementColor(Windows.UI.ViewManagement.UIElementType.PageBackground).ToString();

i've tried that , but it doesnt shows theme....

Seungbin Oh
  • 167
  • 9

1 Answers1

7

uiTheme will return only two color #FF000000(Dark)or #FFFFFFFF (Light) according to system ui theme, so you can go this way. you can fill dark or light color to your some ui element to show current system theme

var DefaultTheme = new Windows.UI.ViewManagement.UISettings();
var uiTheme = DefaultTheme.GetColorValue(Windows.UI.ViewManagement.UIColorType.Background).ToString();
if(uiTheme == "#FF000000")
{
    WindowsThemeText.Text = "Dark";
}
else if(uiTheme == "#FFFFFFFF")
{
    WindowsThemeText.Text = "Light";
}
/*
else
{
    WindowsThemeText.Text = "Some new Updated theme found";
}
*/
Shubham Sahu
  • 1,963
  • 1
  • 17
  • 34
  • 1
    Thank you for your confirming and editing my code to right direction! – Seungbin Oh Feb 17 '18 at 10:04
  • 1
    Unfortunately this will return the "app theme", but not the "windows theme" - they can be different. This can be important when choosing a color for Live Tiles – tipa Mar 09 '21 at 13:14
  • 1
    @tipa The default app theme is returned, which it got from the system. If the app changes this theme, this is not reflected in new UISettings(). – Michael B Nov 13 '21 at 09:37
  • 1
    @MichaelB that's not what I meant. In the Windows settings you have 3 options for the "Theme": Dark, Light and Custom. When you select Custom, you can specify a different Theme (Light or Dark) for both Windows and Apps. Now, with the code above the "app theme" is returned, but not the "Windows theme" (which is what I would call "(Windows) system theme" as asked by the creator of this question) – tipa Nov 14 '21 at 10:05