In this article we will discuss on how to detect theme in Windows Phone 7. It is very important to find out to detect the theme to cusomize the application.
Let's write some code.
Step 1: Create a new Windows Phone Application project. Select Silverlight for Windows Phone installed templates.
Step 2: Replace TitlePanel StackPanel of MainPage.xaml with
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="Theme" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
Step 3: Add TextBlock in the ContentPanel Grid of MainPage.xaml.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Height="30" HorizontalAlignment="Left" Margin="11,80,0,0" Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" Width="329" />
</Grid>
Step 4: Open MainPage.xaml and place below code of MainPage.
public
MainPage()
{
InitializeComponent();
Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"];
if (v == System.Windows.Visibility.Visible)
{
textBlock1.Text = "Selected theme is light!";
}
else
{
textBlock1.Text = "Selected theme is dark!";
}
} Now run the application, "Selected theme is dark will be displayed"