I want to create SolidColorBrush from Hex value such as #ffaacc. How can I do this?
On MSDN, I got :
SolidColorBrush mySolidColorBrush = new SolidCol
If you don't want to deal with the pain of the conversion every time simply create an extension method.
public static class Extensions
{
public static SolidColorBrush ToBrush(this string HexColorString)
{
return (SolidColorBrush)(new BrushConverter().ConvertFrom(HexColorString));
}
}
Then use like this: BackColor = "#FFADD8E6".ToBrush()
Alternately if you could provide a method to do the same thing.
public SolidColorBrush BrushFromHex(string hexColorString)
{
return (SolidColorBrush)(new BrushConverter().ConvertFrom(hexColorString));
}
BackColor = BrushFromHex("#FFADD8E6");