Windows Phone 7检测当前主题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Windows Phone 7检测当前主题相关的知识,希望对你有一定的参考价值。

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

以上是关于Windows Phone 7检测当前主题的主要内容,如果未能解决你的问题,请参考以下文章