在文本块中更改部分文本的颜色 [英] Change color in part of text in textblock

查看:58
本文介绍了在文本块中更改部分文本的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在代码后面更改部分文字字符串的颜色.

I need change color in code behind for part of text string..

我的实例:

textblock1.Text = string1 + string2 + string3;

字符串具有动态值,我想在以蓝色运行程序后显示string2,并且必须在后面的代码中对其进行定义.

String have dynamic values, and i want to string2 display after running the program in blue color and it must be defined in the code behind.

有可能吗?谢谢!

推荐答案

有效

                        textblock1.Inlines.Clear();
                        textblock1.Inlines.Add(new Run(string1));
                        textblock1.Inlines.Add(new Run(string2) { Foreground = Brushes.Blue });

这篇关于在文本块中更改部分文本的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆