Check if user has dark or light theme in WP7 Silverlight (C#)

Thought I would share a small piece of code to check if the user is using a light or dark theme, as it seems some developers forget that you can actually have a white theme too ;)

The following piece of code will make a boolean that is true if the user has the dark theme and false if he/she has white theme:

bool darkTheme = ((Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] == Visibility.Visible);

Then use the boolean to change the theme of your application when necessary. It is also a nice idea to make a static function you can reuse to check whether the user has dark or light theme.

Note: There is also a “PhoneLightThemeVisibility” value in Application.Current.Resources dictionary that can be used in the reversed manner from what is shown above.

1 comment

  • Great tip, exactly what I was searching for!

    BY DAVID . APRIL 18, 2012

Sorry, comments for this entry are closed at this time.