我认为问题标题足以自我解释。我已经通过添加了一些字符串ParagraphControl.Inlines.Add(SomeStringValue)
,但在检索文本内容时遇到了一些麻烦。任何提示?
我试图从Inline
自身获取文本,然后通过String.Join()
我终于设法实现了它。
Text = String.Join(String.Empty, ParagraphControl.Inlines.Select(line => line.ContentStart.GetTextInRun(LogicalDirection.Forward)));
这是我使用的扩展方法。AParagraph
是 a TextElement
,System.Windows.Document 中的其他一些东西也是如此。
public static string GetText(this TextElement textElement)
{
return new TextRange(textElement.ContentStart, textElement.ContentEnd).Text;
}