3

我认为问题标题足以自我解释。我已经通过添加了一些字符串ParagraphControl.Inlines.Add(SomeStringValue),但在检索文本内容时遇到了一些麻烦。任何提示?

我试图从Inline自身获取文本,然后通过String.Join()

4

2 回答 2

4

我终于设法实现了它。

Text = String.Join(String.Empty, ParagraphControl.Inlines.Select(line => line.ContentStart.GetTextInRun(LogicalDirection.Forward)));
于 2015-05-11T10:29:49.410 回答
0

这是我使用的扩展方法。AParagraph是 a TextElement,System.Windows.Document 中的其他一些东西也是如此。

public static string GetText(this TextElement textElement)
{
    return new TextRange(textElement.ContentStart, textElement.ContentEnd).Text;
}

另请参阅https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/how-to-extract-the-text-content-from-a-richtextbox

于 2020-07-08T19:18:38.550 回答