Skip to content

Instantly share code, notes, and snippets.

@jasongaylord
Last active December 17, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongaylord/5680181 to your computer and use it in GitHub Desktop.
Save jasongaylord/5680181 to your computer and use it in GitHub Desktop.
This class can be copied into any of your phone applications. I usually create a file called Theme.cs and paste it in there. In the App.xaml.cs file, update Application_Launching and Application_Activeated to call Theme.Detect(). This will call the static method called Detect which will, in turn, populate the properties listed. I've blogged abou…
public static class Theme
{
public static SolidColorBrush Foreground { get; private set; }
public static ThemeColor CurrentTheme { get; private set; }
public static bool IsLightTheme { get { return CurrentTheme == ThemeColor.Light; } }
public static bool IsDarkTheme { get { return CurrentTheme == ThemeColor.Dark; } }
public enum ThemeColor
{
Light,
Dark
}
public static void Detect()
{
// Determine what the theme background is
Visibility isVisible = (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"];
CurrentTheme = isVisible == Visibility.Visible ? ThemeColor.Light : ThemeColor.Dark;
// Determine the theme foreground
Theme.Foreground = (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment