Skip to content

Instantly share code, notes, and snippets.

@nivesh2
Created April 26, 2013 13:16
Show Gist options
  • Save nivesh2/5467318 to your computer and use it in GitHub Desktop.
Save nivesh2/5467318 to your computer and use it in GitHub Desktop.
detect Theme in Windows Phone app
//Accent color is given by PhoneAccentColor ressource. Its type is System.Windows.Media.Color
using System.Windows.Media;
Color AccentColor()
{
return (Color)Application.Current.Resources["PhoneAccentColor"];
}
//To make a TextBlock theme-aware use the Style property
<TextBlock Style="{StaticResource PhoneTextAccentStyle}"/>
//To make a Rectangle theme-aware use the Fill property:
<Rectangle Fill="{StaticResource PhoneAccentBrush}" />
//To get theme background, you can use PhoneDarkThemeVisibility resource. Its type is System.Windows.Visibility enum
using System.Windows
bool DarkThemeUsed ()
{
return Visibility.Visible == (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"];
}
bool LightThemeUsed()
{
return Visibility.Visible == (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"];
}
...
// Write the theme background value.
if (DarkThemeUsed ())
{
//Set resources according to dark theme
}
else
{
//Set resources according to light theme
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment