0

I need to add the TextRange to flow document without losing formatting done to it in RichTextBox. I am getting RichTextBox.Text which converts it to string and lose all the formatting but I don't want to loose formatting of text read from RichTextBox.

TextRange t = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
String s = t.Text;

FlowDocument fd = new FlowDocument();
  /*
    this snippet works but looses formatting
    Paragraph p = new Paragraph();
    p.Inlines.Add(s);
    fd.Blocks.Add(p);
  */
fd.Blocks.Add(t); // cannot convert TextRange to Block
Jackdaw
  • 7,626
  • 5
  • 15
  • 33
Ali
  • 9
  • 4
  • Hi and welcome to SO. Please edit the question to show what you've tried. Like this we will be able to better understand your problem/question and thus we will be able to better help you. It is best to provide a [MCVE]. For more information, please see [Ask] and take the [Tour]. – quant Nov 16 '18 at 07:26
  • RichTextbox has Document property (guessing it should be with formatting) - Try adding it to Section. – Prateek Shrivastava Nov 16 '18 at 08:02
  • document property is working but it divides the content in to columns – Ali Nov 16 '18 at 08:07

0 Answers0