Posted By

jacob4u2 on 10/01/10


Tagged

c wp7 wp7dev winphone7 winphone


Versions (?)

Windows Phone 7 Detect Current Theme


 / Published in: C#
 

URL: http://jacob4u2.blogspot.com

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.

  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. }

Report this snippet  

You need to login to post a comment.