如何在我的代码中告诉手机所在的“主题”(即Light或Dark)?Windows Phone 7背景主题设置 - 应用程序开发
UPDATE:
OK,做了进一步的研究之后,我能够找到出现做什么,我需要的东西。但是,也许有更好的办法?
想法?
这里是我的发现,回答我的问题,现在:
var backColor = Resources["PhoneBackgroundColor"];
如何在我的代码中告诉手机所在的“主题”(即Light或Dark)?Windows Phone 7背景主题设置 - 应用程序开发
UPDATE:
OK,做了进一步的研究之后,我能够找到出现做什么,我需要的东西。但是,也许有更好的办法?
想法?
这里是我的发现,回答我的问题,现在:
var backColor = Resources["PhoneBackgroundColor"];
在早期的beta版本中,做这件事的方法是检查PhoneBackgroundColor的RGB值,就像其他人指出的那样。然而,这已经改变。
现在这样做的最佳方法是检查“PhoneLightThemeVisibility”这样(即使检查RGB值仍然有效)的可见性:
Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"];
if (v == System.Windows.Visibility.Visible)
{
// Light theme
}
else
{
// Dark theme
}
HTH
+1这是一个很好的做法。 – keyboardP 2010-11-22 01:40:08
目前,检查PhoneBackgroundColor
值似乎是检测主题接受的方法。您可以通过以下代码检查值,该代码来自this post。
private Color lightThemeBackground = Color.FromArgb(255, 255, 255, 255);
private Color darkThemeBackground = Color.FromArgb(255, 0, 0, 0);
private void DisplayState()
{
SolidColorBrush backgroundBrush = Application.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush;
if (backgroundBrush.Color == lightThemeBackground)
{
// you are in the light theme
}
else
{
// you are in the dark theme
}
}
检查RGB值的作品,但新的“PhoneLightThemeVisibility”资源是首选 - 请参阅我的答案。 – mikeesouth 2010-11-21 16:43:11
检查RGB值的作品,但新的“PhoneLightThemeVisibility”资源是首选 - 请参阅我的答案。 – mikeesouth 2010-11-21 16:42:38
http://www.kirupa.com/windowsphone/detecting_the_theme.htm – 2010-11-21 20:42:23
试试这里提供的主题类:https://github.com/ZombieHunter/WP7-Theme – CodeZombie 2011-06-17 08:06:58