Programmatically set TextBlock Foreground Color

后端 未结 4 1354
孤城傲影
孤城傲影 2021-01-31 13:30

Is there a way to do this in Windows Phone 7?

I can reference the TextBlock in my C# Code, but I don\'t know exactly how to then set the foreground color of it.

4条回答
  •  执笔经年
    2021-01-31 14:15

    Foreground needs a Brush, so you can use

    textBlock.Foreground = Brushes.Navy;
    

    If you want to use the color from RGB or ARGB then

    textBlock.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(100, 255, 125, 35)); 
    

    or

    textBlock.Foreground = new System.Windows.Media.SolidColorBrush(Colors.Navy); 
    

    To get the Color from Hex

    textBlock.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFDFD991")); 
    

提交回复
热议问题