user3008134
user3008134

Reputation: 127

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

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

Answers (3)

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33381

You can use ColorConverter.ConvertFromString Method.

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

Upvotes: -1

Pradeep Kesharwani
Pradeep Kesharwani

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

ineffable p
ineffable p

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

Related Questions