Search code examples
c#wpftextboxword-wrap

Break words in textbox (with TextWrapping=Wrap)


I do not know how to describe my problem, but imagine having a TextBox in WPF with a long text. I have set TextWrapping="Wrap" to prevent the whole string being displayed in one line, but I want my sting to be shown as follows:

Lorem ipsum dolor sit amet, consectetur adipiscing el
it. Fusce ligula nulla, cursus finibus mauris vel, rh
oncus blandit sem. Fusce fermentum sed sem a porttito
r. Proin id convallis ex.

Instead of this:

Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Fusce ligula nulla, cursus finibus mauris vel,
rhoncus blandit sem. Fusce fermentum sed sem a
porttitor. Proin id convallis ex.

The difference is, that the first text has a 'hard cut' after every n character - the second text is wrapped, that each line does not exceed a length of n characters


Do I have to insert a \n after every n-th character, or is there a WPF-property, which can solve this for me?


Thank you very much and merry christmas to you all :)


Solution

  • I don't think there is a direct property to achieve the result. TextTrimming property is available only for TextBlock. It is better to add linebreak to achieve the result.