[英]Textblock loses boldness of bold text
I have a TextBlock
我有一个TextBlock
<TextBlock x:Name="TopTextBlock">
Normals words followed by <Bold>Bold words</Bold>
</Textblock>
It displays the text bold. 它以粗体显示文本。
However, if in my C# code I make any alterations to the string such as 但是,如果在我的C#代码中对字符串进行了任何更改,例如
TopTextBlock.Text += " word"
The text will no longer appear bold 文本将不再显示为粗体
Add string in TextBlock Inlines instead of setting Text DP : 在TextBlock Inlines中添加字符串,而不是设置Text DP:
TopTextBlock.Inlines.Add(" word");
Or in case want to add Bold text : 或者,如果要添加粗体文本:
TopTextBlock.Inlines.Add(new Run(" word") { FontWeight = FontWeights.Bold });
The XAML implicitly sets the TextBlock's Inlines
property, whereas in code behind you set the Text
property. XAML隐式设置了TextBlock的Inlines
属性,而在后面的代码中,您设置了Text
属性。 You might however add text to the Inlines collection like this: 但是,您可以像这样将文本添加到Inlines集合中:
TopTextBlock.Inlines.Add(new Run(" word"));
or shorter: 或更短:
TopTextBlock.Inlines.Add(" word");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.