Windows Phone 7 背景主题设置 - 应用程序开发

6

我怎样在代码中判断手机使用的主题(即浅色或深色)?

更新:

经过一些研究,我找到了一个似乎可以满足我的需求的方法。不过,也许还有更好的方法?

你有什么想法吗?

以下是我现在找到的回答:

var backColor = Resources["PhoneBackgroundColor"];

检查 RGB 值是可行的,但更推荐使用新的“PhoneLightThemeVisibility”资源 - 请参见我的答案。 - mikeesouth
http://www.kirupa.com/windowsphone/detecting_the_theme.htm - Den
在这里尝试使用可用的Theme类:https://github.com/ZombieHunter/WP7-Theme - CodeZombie
2个回答

9
在早期的测试版中,这样做的方法是检查PhoneBackgroundColor的RGB值,就像其他人在这里指出的那样。然而,现在情况已经改变。
现在,首选的方法是检查"PhoneLightThemeVisibility"的可见性,如下所示(即使检查RGB值仍然有效):
Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"];
if (v == System.Windows.Visibility.Visible)
{
    // Light theme
}
else
{
    // Dark theme
}

HTH


3

目前,检查PhoneBackgroundColor的值似乎是检测主题的接受方法。你可以通过以下代码检查该值,该代码来自于此帖子

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接