6

有没有办法仅在 TextBlock (或小于整个块的任何数量)中将下划线文本装饰应用于一个字符?

我有一些文本我想输出为“this worf is mispellet”,并在finworf下划线。

我知道你可以这样做:

TextBlock47.TextDecorations = TextDecorations.Underline;

但我不希望整个块都加下划线。

如果做不到这一点,除了 TextBlock 之外,我是否可以使用另一个控件来提供此功能?我研究了富文本,但对于一个简单的效果来说,这似乎是一项非常艰巨的工作。如果这唯一的方法,我该如何在 c# 代码中生成特定格式的文本(10pt,Courier New,一个字符下划线)?

4

2 回答 2

21

您可以在TextBlock中使用Underline

<TextBlock Name="textBlock47">
  this wor<Underline>f</Underline> is misspelt
</TextBlock>

或者

textBlock47.Inlines.Add(new Run("this wor"));
textBlock47.Inlines.Add(new Underline(new Run("f")));
textBlock47.Inlines.Add(new Run(" is misspelt"));
于 2010-10-08T03:47:21.740 回答