在Windows Phone 7中有没有办法做到这一点?
我可以在我的C#代码中引用TextBlock,但我不知道如何设置它的前景色。
myTextBlock.Foreground =
//not a clue...
感谢
在Windows Phone 7中有没有办法做到这一点?
我可以在我的C#代码中引用TextBlock,但我不知道如何设置它的前景色。
myTextBlock.Foreground =
//not a clue...
感谢
textBlock.Foreground = new SolidColorBrush(Colors.White);
前景需要一个画刷,所以您可以使用
textBlock.Foreground = Brushes.Navy;
如果您想使用来自RGB或ARGB的颜色,则
textBlock.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(100, 255, 125, 35));
或者textBlock.Foreground = new System.Windows.Media.SolidColorBrush(Colors.Navy);
从十六进制获取颜色
textBlock.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFDFD991"));
您可以使用Brushes.White
来设置前景色。
myTextBlock.Foreground = Brushes.White;
Brushes
类位于System.Windows.Media
命名空间中。
或者在光标停留在未知类名上时,按下Ctrl+.即可自动添加using
指令。
获取十六进制颜色值的颜色。
using System.Windows.Media;
Color color = (Color)ColorConverter.ConvertFromString("#FFDFD991");
然后设置前景色。
textBlock.Foreground = new System.Windows.Media.SolidColorBrush(color);