How can i change the background color of a stackpanel programmatically in windows phone app?

。_饼干妹妹 提交于 2019-12-23 19:13:46

问题


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??


回答1:


statusPanel.Background =  new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0));

If this answered your question, Please check right on left side.




回答2:


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");



回答3:


You can use ColorConverter.ConvertFromString Method.

statusPanel.Background =
      new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF010203"));


来源:https://stackoverflow.com/questions/22346949/how-can-i-change-the-background-color-of-a-stackpanel-programmatically-in-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!