如何只为括号中的文本着色

时间:2021-02-09 17:46:47

标签: c# wpf

在 WPF (C#) 应用程序中,我只想为括号中的文本着色。有什么帮助吗?
例如: 在本文中:
使用 Lorem Ipsum 的重点在于它或多或少地具有正态分布的字母,而不是使用“这里的内容,这里的内容”,有时是故意的(注入幽默等) .

...(injected humour and the like) 必须为红色。

其实我是用 RichTextBox 来显示文字的..

1 个答案:

答案 0 :(得分:0)

您可以使用 Run 控件内的多个 TextBlock 元素实现此目的。文本仍将在 TextBlock 的边界内流动。例如...

<TextBlock MaxWidth="100" TextWrapping="Wrap">
    <Run Text="Standard Text " />
    <Run Foreground="Red" Text="red text" />
    <Run Text=" more standard text." />
</TextBlock>