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??
statusPanel.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0));
如果这回答了您的问题,请在左侧检查。
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");
You can use ColorConverter.ConvertFromString Method.
statusPanel.Background =
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF010203"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.