Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Phone 7 Background Theme setting - App development

How can I tell in my code what "theme" the phone is on (i.e. Light or Dark)?

UPDATE:

OK, after doing a little more research I was able to find something that appears to do what I need. However, maybe there is a better way?

Thoughts?

Here is what I found that answers my question for now:

var backColor = Resources["PhoneBackgroundColor"];
like image 331
webdad3 Avatar asked Nov 21 '10 14:11

webdad3


2 Answers

In the early beta releases the way to do this was checking the RGB values of PhoneBackgroundColor just as pointed out by others here. However this has changed.
Now the preferred way of doing this is checking the Visibility of "PhoneLightThemeVisibility" as such (even though checking RGB values still work):

Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"];
if (v == System.Windows.Visibility.Visible)
{
    // Light theme
}
else
{
    // Dark theme
}

HTH

like image 154
mikeesouth Avatar answered Jan 04 '23 05:01

mikeesouth


At the moment, checking the value of PhoneBackgroundColor seems to be the accepted method of detecting the theme. You can check the value by the following code, which is from this post.

private Color lightThemeBackground = Color.FromArgb(255, 255, 255, 255);
private Color darkThemeBackground = Color.FromArgb(255, 0, 0, 0);




private void DisplayState()
{

SolidColorBrush backgroundBrush = Application.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush;

if (backgroundBrush.Color == lightThemeBackground)
{

// you are in the light theme

}
else
{

// you are in the dark theme

}

}
like image 43
keyboardP Avatar answered Jan 04 '23 04:01

keyboardP