WP7 - Assessing theme color
For a WP7 App I want to use an additional color to contrast whatever the the current theme color is.
I decided to make the contrast color 'Red' unless the theme color was already 'Red' in which case I would male the contract Color ' Blue'
But the following code does not work as it does not detect the theme color as 'Red' even though it has been set that way and is certainly showing that way in the app.
private void AssessContrastColor()
{
System.Diagnostics.Debug.WriteLine("In assess color");
SolidColorBrush themeBrush = App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush;
Color themeColor = themeBrush.Color;
SolidColorBrush contrastBrush = new SolidColorBrush();
// contrastBrush.Color = ControlPaint.Light(themeColor);
if (themeColor == Colors.Red)
{
开发者_C百科contrastBrush.Color = Colors.Blue;
}
else contrastBrush.Color = Colors.Red;
_ContrastThemeBrush = contrastBrush;
}
The code seems pretty straightforward, but, when looking at this through debugger, the Phone accent color when I get it (when its Red) is not #FFFF0000 but something a little different.
Just as an aside to this, was looking to create the contrast color as one that was a bit lighter than the theme color, looked around and it seemed like it could be quote a bit of code, but then stumbled across the 'ControlPaint.Light call' which seemed ideal, but doesnt seem to be an option uder WP7? Hence commented out above.
Any advice appreciated. Thanks
This would be because the Accent colour isn't Red
, but something close to it, to be precise #E51400
You can find a list of all the colours and how to use them here. And for future proofing the answer, a list of all the colours:
Blue #1BA1E2
Brown #A05000
Green #339933
Lime #8CBF26
Magenta #FF0097
Orange #F09609
Pink #E671B8
Purple #A200FF
Red #E51400
Viridian #00ABA9
But I would strongly recommend against changing the contrast colours. You're likely to make content less readable.
If you determine a custom colour based on the accent colour, it will likely break when used by the eleventh (vendor specific) colour. From the documentation:
Your application should be aware of this extra color and not make assumptions on just the 10 system-wide colors. For example, do not have code that checks for the standard 10 accent colors and then performs a specific operation; an eleventh color may break the operation
精彩评论