Textblock 失去了粗体文本的粗体度 [英] Textblock loses boldness of bold text

查看:43
本文介绍了Textblock 失去了粗体文本的粗体度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TextBlock

<TextBlock x:Name="TopTextBlock">
   Normals words followed by <Bold>Bold words</Bold>
</Textblock>

它以粗体显示文本.

但是,如果在我的 C# 代码中我对字符串进行了任何更改,例如

However, if in my C# code I make any alterations to the string such as

TopTextBlock.Text += " word"

文本将不再显示为粗体

推荐答案

在 TextBlock Inlines 中添加字符串而不是设置 Text DP :

Add string in TextBlock Inlines instead of setting Text DP :

TopTextBlock.Inlines.Add(" word");

或者如果想添加粗体文本:

Or in case want to add Bold text :

TopTextBlock.Inlines.Add(new Run(" word") { FontWeight = FontWeights.Bold });

这篇关于Textblock 失去了粗体文本的粗体度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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