Reputation: 127
I just want set the background property of StackPanel , currently i setting it by the following code,
statusPanel.Background = new SolidColorBrush(Colors.Cyan);
But i just want to set a hexadecimal value. How can i do it??
Upvotes: 4
Views: 8117
Reputation: 33381
You can use ColorConverter.ConvertFromString Method.
statusPanel.Background =
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF010203"));
Upvotes: -1
Reputation: 1478
Use this function:
public SolidColorBrush GetColorFromHexa(string hexaColor)
{
byte R = Convert.ToByte(hexaColor.Substring(1, 2), 16);
byte G = Convert.ToByte(hexaColor.Substring(3, 2), 16);
byte B = Convert.ToByte(hexaColor.Substring(5, 2), 16);
SolidColorBrush scb = new SolidColorBrush(Color.FromArgb(0xFF, R, G, B));
return scb;
}
Usage:
statusPanel.Background = GetColorFromHexa("#RRGGBB");
Upvotes: 1
Reputation: 1189
statusPanel.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0));
If this answered your question, Please check right on left side.
Upvotes: 6