简体   繁体   English

WPF:装饰文本块中文本部分的最佳方法

[英]WPF: best way to decorate parts of a text in a textblock

I have a textblock with a long text that is displayed in several lines (as textblock width is not enough to display every letter). 我有一个长文本的文本块,显示在几行中(因为文本块宽度不足以显示每个字母)。

I'd like to have some words are bold, and it's important to keep text displayed in several lines as before. 我希望有些单词是粗体的,并且保持文本显示在几行中是很重要的。 How would you decorate parts of a text? 你会如何装饰文本的一部分?

"the quick brown fox jumped over the lazy yellow dog ." “快速的棕色狐狸跳过懒惰的黄狗 。”

If TextBlock abilities are not enough (thank you, @BoltClock) may be I should split TextBlock into several ones, or manipulate TextBlock.Inlines or something? 如果TextBlock能力不够(谢谢,@ Bollock)可能是我应该将TextBlock分成几个,或者操纵TextBlock.Inlines或什么?

You can use runs: 你可以使用运行:

<TextBlock.Inlines>
    <Run Text="the quick brown " />
    <Run FontStyle="Bold" Text="fox" />
    <Run Text=" jumped over the lazy yellow " />
    <Run FontStyle="Bold" Text="dog" />
    <Run Text="." />
</TextBlock.Inlines>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM