Windows Phone 7 Detect Current Theme


/ Published in: C#
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. // An enum to specify the theme.
  2. public enum AppTheme
  3. {
  4. Dark = 0,
  5. Light = 1
  6. }
  7.  
  8. // Detecting the current theme.
  9. private static Color lightThemeBackground = Color.FromArgb(255, 255, 255, 255);
  10. private static Color darkThemeBackground = Color.FromArgb(255, 0, 0, 0);
  11. private static SolidColorBrush backgroundBrush;
  12. internal static AppTheme CurrentTheme
  13. {
  14. get
  15. {
  16. if ( backgroundBrush == null )
  17. backgroundBrush = Application.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush;
  18.  
  19. if (backgroundBrush.Color == lightThemeBackground)
  20. return AppTheme.Light;
  21. else if (backgroundBrush.Color == darkThemeBackground)
  22. return AppTheme.Dark;
  23.  
  24. return AppTheme.Dark;
  25. }
  26. }

URL: http://jacob4u2.blogspot.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.