Convert RGB colour value to Brush
using Windows.UI;
//************************************************
//************************************************
//********** CONVERT RGB TO BRUSH COLOR **********
//************************************************
//************************************************
private Brush ConvertRgbHexToBrushColor(string hex)
{
try
{
if (hex.StartsWith("#"))
hex = hex.Substring(1);
if (hex.Length != 6) throw new Exception("Color not valid");
return new SolidColorBrush(ColorHelper.FromArgb(
0xff,
byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber),
byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber),
byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber)));
}
catch (Exception )
{
return new SolidColorBrush(ColorHelper.FromArgb(0xff, 0xff, 0xff, 0xff));
}
}
Convert RGB color value to Color
using Windows.UI;
//******************************************
//******************************************
//********** CONVERT RGB TO COLOR **********
//******************************************
//******************************************
private Color ConvertRgbHexToColor(string hex)
{
try
{
if (hex.StartsWith("#"))
hex = hex.Substring(1);
if (hex.Length != 6) throw new Exception("Color not valid");
return Color.FromArgb(
0xff,
byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber),
byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber),
byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
}
catch (Exception )
{
return Color.FromArgb(0xff, 0xff, 0xff, 0xff);
}
}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.