[英]Change TextBlock foreground for specific letters
is it possible to change the foreground of a TextBlock for specific letters? 是否可以更改特定字母的TextBlock的前景? Say for the last three I choose red, instead of the default black. 说出最后三个,我选择红色,而不是默认的黑色。
Can I command this via C#? 我可以通过C#命令吗?
You can do this by creating your text as a series of Run
s. 您可以通过将文本创建为一系列Run
。
<TextBlock>
<Run>C</Run>
<Run Foreground="Red">ar</Run>
</TextBlock>
Or to do it from codebehind: 或从背后的代码做到这一点:
var textblock = new TextBlock();
textBlock.Inlines.Add(new Run("C"));
textBlock.Inlines.Add(new Run("ar") {Foreground = new SolidColorBrush(Colors.Red)});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.