![](/img/trans.png)
[英]How to set Background image for a stackpanel in item template in windows phone app
[英]How can i change the background color of a stackpanel programmatically in windows phone app?
我只想設置StackPanel的背景屬性,目前我通過以下代碼設置它,
statusPanel.Background = new SolidColorBrush(Colors.Cyan);
但我只想設置一個十六進制值。 我該怎么做??
statusPanel.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0));
如果這回答了您的問題,請在左側檢查。
使用此功能:
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;
}
用法:
statusPanel.Background = GetColorFromHexa("#RRGGBB");
您可以使用ColorConverter.ConvertFromString方法。
statusPanel.Background =
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF010203"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.