How to detect the 'Theme Background' being used in WP7
This article explains how to determine whether the dark or light Windows Phone theme is visible.
See Also
Article Metadata
Tested with
SDK: Windows Phone SDK 7.1
Devices(s): Nokia Lumia 800
Compatibility
Platform(s): Windows Phone 7.5 (Mango)
Article
Created: sreerajvr
(06 Apr 2012)
Last edited: hamishwillee
(30 Nov 2012)
Introduction
Windows Phone 7 has either a dark (black) or light (white) theme. In order to get the best result for your app's colour scheme it can be useful to be able to determine which theme is being used.
The following code snippet shows how you can determine the theme by comparison of the "PhoneForegroundColor" to the value for black ("#FFFFFFFF"). An alternative, as outlined in Determining Theme Background and Accent Color (MSDN) is to get the Visibility of the PhoneDarkThemeVisibility
Source Code
XAML
<Grid x:Name="LayoutRoot" Background="Transparent">
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
</Grid>
CSharp
public MainPage()
{
InitializeComponent();
Color themebackground = (Color)Application.Current.Resources["PhoneForegroundColor"];
if (themebackground.ToString() == "#FFFFFFFF")
{
this.PageTitle.Text = "Dark ";
}
else
{
this.PageTitle.Text = "Light ";
}
}
Summary
This code snippet shows how to determine whether the dark or light theme is visible.

