Friday, October 26, 2012

Detect Windows Phone Theme

Some times an application needs to know which theme is currently in use on the device so it can adjust it's UI.

The PhoneLightThemeVisibility key indicates the visibility of the light theme.
The PhoneDarkThemeVisibility key indicates the visibility of the dark theme.

In XAML you can do something like:
<TextBlock Visibility="{StaticResource PhoneLightThemeVisibility}" />
<TextBlock Visibility="{StaticResource PhoneDarkThemeVisibility}" />
You can use a converter to manipulate other properties that are not of type Visibility.

In C#:
Visibility LightThemeVisibility = (Visibility)Resources["PhoneLightThemeVisibility"];
Visibility DarkThemeVisibility = (Visibility)Resources["PhoneDarkThemeVisibility"];

No comments:

Post a Comment