我怎样在代码中判断手机使用的主题(即浅色或深色)?
更新:
经过一些研究,我找到了一个似乎可以满足我的需求的方法。不过,也许还有更好的方法?
你有什么想法吗?
以下是我现在找到的回答:
var backColor = Resources["PhoneBackgroundColor"];
我怎样在代码中判断手机使用的主题(即浅色或深色)?
更新:
经过一些研究,我找到了一个似乎可以满足我的需求的方法。不过,也许还有更好的方法?
你有什么想法吗?
以下是我现在找到的回答:
var backColor = Resources["PhoneBackgroundColor"];
Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"];
if (v == System.Windows.Visibility.Visible)
{
// Light theme
}
else
{
// Dark theme
}
HTH
目前,检查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
}
}