(1)方式一:
Color color1 = (Color)System.Windows.Media.ColorConverter.ConvertFromString("#E0E0E0");
(2)方式二:
Color color2 = ConvertToColor("#E0E0E0");
public static System.Windows.Media.Color ConvertToColor(string value)
{
int r = 0, g = 0, b = 0;
if (value.StartsWith("#"))
{
int v = Convert.ToInt32(value.Substring(1), 16);
r = (v >> 16) & 255; g = (v >> 8) & 255; b = v & 255;
}
return System.Windows.Media.Color.FromRgb(Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b));
}