Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :)

like image 934
unknown6656 Avatar asked Dec 24 '15 09:12

unknown6656


2 Answers

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.

like image 168
Subru Avatar answered Sep 21 '22 18:09

Subru


Just try it with TextAlignment="Justify"

<TextBox TextAlignment="Justify" TextWrapping="Wrap" Height="250" MinWidth="250" Width="250" Text="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."/>
like image 27
Justin CI Avatar answered Sep 20 '22 18:09

Justin CI