November 25, 2010

Get Color from Hex values in Silverlight

Since Silverlight does not support System.Drawing.ColorTranslator the following method can be used to convert Html Color values to a Color object.


public static Color GetColor(string htmlColor) {
            return Color.FromArgb(255,
                Convert.ToByte(htmlColor.Substring(1, 2), 16),
                    Convert.ToByte(htmlColor.Substring(3, 2), 16),
                    Convert.ToByte(htmlColor.Substring(5, 2), 16)
            );
        }

No comments: