How can I access the current colors of themes?

I have a Windows Phone 8 application that displays some HTML (from an RSS / Atom feed) in a WebBrowser . To make this HTML look more native, I run it through a simple mobilizer that makes layout, font, images, etc. More natural by rewriting the HTML structure and setting some CSS.

It works great. However, I would like to make sure that the CSS created by the mobilizer applies colors from the user's current theme to the background, text, links, etc. Although I can apply colors to themes in a XAML document, I have not found a way to get these colors from C #. Is it possible? If so, how?

+4
source share
1 answer

You can get accent colors as shown here .

 // Determine the accent color. Color currentAccentColorHex = (Color)Application.Current.Resources["PhoneAccentColor"]; 

This is not the most beautiful way to get a color name if that is what you want, but you can use it compatible with WP7 and 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; 
+2
source

All Articles