我有一个Windows Phone 8应用程序,它在WebBrowser
控件中呈现一些HTML(来自RSS / Atom提要)。为了使这个HTML看起来更原生,我通过一个简单的动员器运行它,通过重写HTML结构和设置一些CSS,使布局,字体,图像等看起来更原生。
这很好用。但是,我想确保动员者生成的CSS将用户当前主题的颜色应用于背景,文本,链接等。虽然我可以在XAML文档中应用主题颜色,但我还没有找到办法从C#中获取这些颜色。这可能吗?如果是这样,怎么样?
答案 0 :(得分:2)
您可以获得如here所示的强调色。
// Determine the accent color.
Color currentAccentColorHex = (Color)Application.Current.Resources["PhoneAccentColor"];
获取颜色名称不是最漂亮的方法,如果这是您想要的,但您可以使用与WP7和WP8兼容的颜色。
string currentAccentColor = "";
switch (currentAccentColorHex.ToString())
{
case "#FF1BA1E2": currentAccentColor = "blue"; break;
case "#FFA05000": currentAccentColor = "brown"; break;
case "#FF339933": currentAccentColor = "green"; break;
case "#FFE671B8": currentAccentColor = "pink"; break;
case "#FFA200FF": currentAccentColor = "purple"; break;
case "#FFE51400": currentAccentColor = "red"; break;
case "#FF00ABA9": currentAccentColor = "teal (viridian)"; break;
// Lime changed to #FFA2C139 in Windows Phone OS 7.1.
case "#FF8CBF26":
case "#FFA2C139": currentAccentColor = "lime"; break;
// Magenta changed to # FFD80073 in Windows Phone OS 7.1.
case "#FFFF0097":
case "#FFD80073": currentAccentColor = "magenta"; break;
// #FFF9609 (previously orange) is named mango in Windows Phone OS 7.1.
case "#FFF09609": currentAccentColor = "mango (orange)"; break;
// Mobile operator or hardware manufacturer color
default: currentAccentColor = "custom eleventh color"; break;
}
// Write the current accent color.
textBlock2.Text = "accent color = " + currentAccentColor;