Return to Snippet

Revision: 32654
at October 1, 2010 06:15 by jacob4u2


Initial Code
// An enum to specify the theme.
public enum AppTheme
{
    Dark = 0,
    Light = 1
}

// Detecting the current theme.
private static Color lightThemeBackground = Color.FromArgb(255, 255, 255, 255);
private static Color darkThemeBackground = Color.FromArgb(255, 0, 0, 0);
private static SolidColorBrush backgroundBrush;
internal static AppTheme CurrentTheme
{
    get
    {
        if ( backgroundBrush == null )
            backgroundBrush = Application.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush;

        if (backgroundBrush.Color == lightThemeBackground)
            return AppTheme.Light;
        else if (backgroundBrush.Color == darkThemeBackground)
            return AppTheme.Dark;
                
        return AppTheme.Dark;
    }
}

Initial URL
http://jacob4u2.blogspot.com

Initial Description
Add this code to your App.xaml.cs inside your App class to enable a static property that will give you the current theme at runtime.

Initial Title
Windows Phone 7 Detect Current Theme

Initial Tags
c

Initial Language
C#