2012-02-21 53 views

回答

3

你可以在手机上的主题(暗/灯光),在更短的方式(对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 
    } 
} 

而不是返回一个字符串包含'红',你可以返回一个'真正的'颜色。为此,您必须更改方法的返回类型和值。

希望这会有所帮助!

+0

错误“应用程序”并不在当前上下文中存在的名称\t 错误类型或命名空间名称“颜色'在命名空间中不存在'System.Windows.Media' 奇怪的错误:( – DanTonyBrown 2012-02-22 01:24:19

+0

请确保您的项目中有对“System.Windows.dll”的引用 – Abbas 2012-02-22 08:30:16

+0

仍然得到应用程序不存在:(颜色是固定但是:) – DanTonyBrown 2012-02-22 10:38:30

0

您可以从资源中获取当前主题,例如获取像这样的背景颜色。在应用程序中,您可以在Application_Launching和Application_Activated中检查这一点,以查看应用程序在后台时是否更改了主题。

我敢肯定,你可以做类似的事情在XNA游戏:

public enum PhoneTheme 
    { 
     Light, 
     Dark 
    }; 

公共静态PhoneTheme CurrentTheme {获得;私人设置; }

继您激活/启动代码:

string theme = Resources["PhoneBackgroundColor"].ToString(); 

CurrentTheme = theme == "#FF000000" 
         ? PhoneTheme.Dark 
         : PhoneTheme.Light; 
+0

错误名称“资源”不存在于当前上下文存在 – DanTonyBrown 2012-02-22 10:33:46

相关问题