Programmatically set TextBlock Foreground Color

后端 未结 4 1355
孤城傲影
孤城傲影 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:02

    To get the Color from Hex.

    using System.Windows.Media;
    
    Color color = (Color)ColorConverter.ConvertFromString("#FFDFD991");
    

    and then set the foreground

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

提交回复
热议问题