Break words in a text field (using TextWrapping = Wrap)

I donโ€™t know how to describe my problem, but imagine that I have a TextBox in WPF with long text. I set TextWrapping="Wrap" so that the whole line is displayed on one line, but I want my message 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 each n characters - the second text is wrapped that each line does not exceed the length of n characters


Do I need to insert \n after every nth character, or is there a WPF property that can solve this for me?


Thank you very much and merry Christmas to all of you :)

+7
c # wpf textbox textwrapping
source share
2 answers

I do not think that to achieve the result there is direct ownership. TextTrimming property is available only for TextBlock . To achieve the result, it is better to add linebreak.

+3
source share

Just try using 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."/> 
+2
source share

All Articles