Last active
December 17, 2015 22:09
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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