Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RichTextBox in WPF does not have an property as .Lines?

is there an equivalent to .Lines of winForms in WPF?

I'm using this currently:

var textRange = new TextRange(TextInput.Document.ContentStart, TextInput.Document.ContentEnd);
string[] lines = textRange.Text.Split('\n');
like image 510
Jack Avatar asked Jan 25 '12 02:01

Jack


1 Answers

RichTextBox is a FlowDocument type and that does not have a Lines property. What you are doing seems like a good solution. You may want to use IndexOf instead of split.

You can also add an extension method like the article suggests:

public static long Lines(this string s)
{
    long count = 1;
    int position = 0;
    while ((position = s.IndexOf('\n', position)) != -1)
        {
        count++;
        position++;         // Skip this occurance!
        }
    return count;
}
like image 86
Raj Ranjhan Avatar answered Oct 06 '22 01:10

Raj Ranjhan