0

Answers to similar questions conclude that setting FlowDocument PageWidth to a large number is the simplest way to effectively programatically disable the auto-word wrapping feature in WPF RichTextBox. There are at least 2 unique issues with this: firstly an arbitrary word wrap threshold; secondly a fixed horizontal scrollbar that does not automatically adjust to the width of the content.

After some testing, I found that the maximum allowable value for PageWidth is only 1,000,000 despite it being a double.

This is what I am considering using, but it looks like a bodge job and it has the disadvantages I mentioned above:

//Disable auto-word wrap
MainRtb.Document.PageWidth = 1000000d;

//Enable auto-word wrap
MainRtb.Document.PageWidth = double.NaN; //default value

Any alternative methods for disabling/enabling word wrap programatically?

Micsupreeme
  • 55
  • 10
  • Does this answer your question? [C#/WPF: Disable Text-Wrap of RichTextBox](https://stackoverflow.com/questions/1368047/c-wpf-disable-text-wrap-of-richtextbox) – Groger Sep 17 '21 at 18:46
  • Hi @Groger, not really, this is one of the threads I referred to where they simply set the PageWidth to a large number. I am interested in alternatives. – Micsupreeme Sep 17 '21 at 19:00
  • You want to know if there is an alternative. According to this answer (which references the official documentation from microsoft), the answer is no. – Groger Sep 17 '21 at 19:42
  • That answer is a workaround that even says "do something like this", which implies there are other ways to implement it. I shouldn't even have to mention that there are usually multiple ways to do things. – Micsupreeme Sep 17 '21 at 20:28

0 Answers0