Search code examples
c#wpfrichtextboxtextblock

RichTextBox in WPF - Getting last block of text


Could anybody share the idea how to get the last block of a RichTextBox's document in WPF? I tried with code:

Block pg = box.Document.ContentEnd.Paragraph.PreviousBlock;
box.Document.Blocks.Remove(pg);

But it doesn't work (the first line is throwing exceptions).


Solution

  • I think this must help you:

    box.Document.Blocks.Remove(box.Document.Blocks.LastBlock)