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"];
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
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With