1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
namespace SilverlightApplication21
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
const string INACTIVESTEPCOLOR = "#FFB2B4A8";
const string ACTIVESTEPCOLOR = "#FF7D00";
SolidColorBrush ActiveSolidColor = new SolidColorBrush(ColorC.HexColor(ACTIVESTEPCOLOR));
SolidColorBrush InActiveSolidColor = new SolidColorBrush(ColorC.HexColor(INACTIVESTEPCOLOR));
// si Active
comboBox1.Background = ActiveSolidColor;
// si non active
comboBox1.Background = InActiveSolidColor;
}
}
static class ColorC
{
public static Color HexColor(String hex)
{ //remove the # at the front
hex = hex.Replace("#", "");
byte a = 255;
byte r = 255;
byte g = 255;
byte b = 255;
int start = 0;
//handle ARGB strings (8 characters long)
if (hex.Length == 8)
{
a = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
start = 2;
}
//convert RGB characters to bytes
r = byte.Parse(hex.Substring(start, 2),
System.Globalization.NumberStyles.HexNumber);
g = byte.Parse(hex.Substring(start + 2, 2), System.Globalization.NumberStyles.HexNumber);
b = byte.Parse(hex.Substring(start + 4, 2), System.Globalization.NumberStyles.HexNumber);
return Color.FromArgb(a, r, g, b);
}
}
} |
Partager