3

I think the question title is self explaining enough. I've added some strings via ParagraphControl.Inlines.Add(SomeStringValue) and I'm getting some troubles retrieving the text content. Any tip?

I've tried to get the text from the Inline itself and then flatten the string collection via String.Join()

Miguel A. Arilla
  • 5,058
  • 1
  • 14
  • 27

2 Answers2

4

I finally managed to achieve it.

Text = String.Join(String.Empty, ParagraphControl.Inlines.Select(line => line.ContentStart.GetTextInRun(LogicalDirection.Forward)));
Miguel A. Arilla
  • 5,058
  • 1
  • 14
  • 27
0

Here's an extension method I use. A Paragraph is a TextElement, as are some other things in System.Windows.Document.

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

See also https://learn.microsoft.com/en-us/dotnet/framework/wpf/controls/how-to-extract-the-text-content-from-a-richtextbox

Sorensen
  • 833
  • 1
  • 9
  • 13