如何在我的代碼中告訴手機所在的「主題」(即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