如何在Windows Phone应用程序中通过编程方式更改StackPanel的背景颜色?

4

我想设置 StackPanel 的背景属性,目前我是通过以下代码进行设置的:

statusPanel.Background = new SolidColorBrush(Colors.Cyan);

但我只想设置一个十六进制的值。我该怎么做?


这是一个重复的问题(只是不同的颜色属性):https://dev59.com/3H3aa4cB1Zd3GeqPdXRy#22323969 - WiredPrairie
3个回答

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

如果这回答了你的问题,请在左侧检查右侧。

1
使用这个函数:

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

-1

它在Windows Phone上不可用。 - WiredPrairie

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接