views:

74

answers:

2

Is there a way to tell if the user has selected a Light or Dark theme?

Thanks!

A: 

If you intend to detect the theme in code, then here is a solution -

var backColor = Resources["PhoneBackgroundColor"];
if (backColor.ToString() == "#FF000000")
    // Dark theme selected => do something
else
    // Light theme selected => do something

HTH, indyfromoz

indyfromoz
This was fine before but the RTM introduced the `PhoneLightThemeVisibility` resource.
Matt Lacey
+3  A: 

There is a property to test for this, rather that comparing the actual resource color.

Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"]; 

if (v == System.Windows.Visibility.Visible)
{
    // Is light theme
}
else
{
    // Is dark theme
}
Matt Lacey
OK, I guess that works. I did share the concerns of others on the linked thread about what to do when / if new themes appear. But I guess this will be fine for the upcoming release...
will
Worrying about things that aren't even rumoured yet (such as other themes) isn't likley to be productive. A new theme would likely cause lots of issues for everyone creating an app which uses themeing. Worry about it if and when it's announced. (I don't think there will be - at least not until WP8)
Matt Lacey