Detect Dark/Light theme

In this post I will show how to detect which theme (dark/light) user selected in system settings. When designing your application, as long as you don’t change the default brushes, it is possible that you wont need this at all, because operating system will automatically adjust your application colors to match the colors defined by the Dark or Light theme.

With that said, there are times you may need this, either you made some custom control and you want to be theme-aware or you want to your app to look different depending on the theme selection.

To detect which theme was selected you have to check local resource PhoneLightThemeVisibility, like in code below:

var v = (Visibility)Resources["PhoneLightThemeVisibility"];
if (v == Visibility.Visible) //if this is true, "Light" theme was selected
{
//do something
else
{
//do something

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s