你可以在手机上的主题(暗/灯光),在更短的方式(对XNA工程太):
Visibility darkBackgroundVisibility = (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"];
if(darkBackgroundVisibility == Visibility.Visible)
//Theme is Dark
else
//Theme is Light
要获得AccentColor,您需要更多代码(我从MSDN上的这篇文章中获得:How to: Apply Theme Resources for Windows Phone)。为了便于阅读,我缩短了switch-statement中的代码并将其放入方法中。我也在一个XNA应用程序中测试了这个,并且这个工作正常! :)
var currentAccentColorHex = (System.Windows.Media.Color)Application.Current.Resources["PhoneAccentColor"];
string currentAccentColor = ColorNameFromHex(currentAccentColorHex);
private string ColorNameFromHex(System.Windows.Media.Color hexColor)
{
switch(hexColor.ToString())
{
case "#FF1BA1E2": return "Blue";
case "#FFA05000": return "Brown";
case "#FF339933": return "Green";
case "#FFE671B8": return "Pink";
case "#FFA200FF": return "Purple";
case "#FFE51400": return "Red";
case "#FF00ABA9": return "Teal";
case "#FF8CBF26":
case "#FFA2C139": return "Lime";
case "#FFFF0097":
case "#FFD80073": return "Magenta";
case "#FFF09609": return "Mango";
default: return "custom eleventh color"; //Manufacturer color
}
}
而不是返回一个字符串包含'红',你可以返回一个'真正的'颜色。为此,您必须更改方法的返回类型和值。
希望这会有所帮助!
错误“应用程序”并不在当前上下文中存在的名称\t 错误类型或命名空间名称“颜色'在命名空间中不存在'System.Windows.Media' 奇怪的错误:( – DanTonyBrown 2012-02-22 01:24:19
请确保您的项目中有对“System.Windows.dll”的引用 – Abbas 2012-02-22 08:30:16
仍然得到应用程序不存在:(颜色是固定但是:) – DanTonyBrown 2012-02-22 10:38:30