我可以动态地使TextBlock.Text不同颜色的一部分? [英] Can I dynamically make part of the TextBlock.Text to different colour?
本文介绍了我可以动态地使TextBlock.Text不同颜色的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的TextBlock在我的主要形式。我的应用程序运行过程中设置文本属性设置为不同的字符串。
我希望能够特殊字符串的颜色部分。
伪代码:
如果(A&小于0)txbStatus的.text =的String.Format({0}< RED> {1}< / RED>中,A,b);
,否则txbStatus.Text =的String.Format({0}<蓝色和GT; {1}< / RED>中,A,B);
解决方案
您可以分割你的字符串ü希望的方式,然后使用的foreach()
循环为拆分字符串尝试
TextBlockName。 Inlines.Add(新运行(彩色文本){前景= Brushes.Blue});
I have TextBlock in my main form. I set the Text property to different strings during the application run.
I would like to be able to colour parts of particular strings.
Pseudo code:
if(a < 0) txbStatus.Text = string.Format("{0} <RED>{1}</RED>", a, b);
else txbStatus.Text = string.Format("{0} <BLUE>{1}</RED>", a, b);
解决方案
You can split your string the way u want and then using a foreach()
loop for that split string try
TextBlockName.Inlines.Add(new Run("colored text") {Foreground = Brushes.Blue});
这篇关于我可以动态地使TextBlock.Text不同颜色的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文