更改文本块中部分文本的颜色
本文关键字:文本 颜色 中部 | 更新日期: 2023-09-27 18:30:11
我需要更改代码后面文本字符串部分的颜色。。
我的例子:
textblock1.Text = string1 + string2 + string3;
字符串具有动态值,我希望在运行程序后以蓝色显示字符串2,并且它必须在后面的代码中定义。
有可能吗?非常感谢。
正在工作的
textblock1.Inlines.Clear();
textblock1.Inlines.Add(new Run(string1));
textblock1.Inlines.Add(new Run(string2) { Foreground = Brushes.Blue });
我希望这能帮助你:
<TextBlock FontSize="16">
<Run Foreground="Red">Your_Text_1</Run>
<Run Foreground="Orange">Your_Text_2</Run>
<Run Foreground="purple">Your_Text_3</Run>
</TextBlock>
您可以使用"Run"例如:"Run Name="Value_from_codebehind"/>"
在后面的代码中附加值