中断文本框中的单词(使用TextWrapping = Wrap)

时间:2022-05-18 20:33:56

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:

我不知道如何描述我的问题,但想象在WPF中使用长文本的TextBox。我已经设置TextWrapping =“Wrap”以防止整个字符串显示在一行中,但我希望我的刺痛显示如下:

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

区别在于,第一个文本在每n个字符后面都有一个“硬切” - 第二个文本被包装,每行不超过n个字符的长度


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

我是否必须在每第n个字符后插入\ n,或者是否有WPF属性,这可以为我解决这个问题?


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

非常感谢你,祝大家圣诞快乐:)

2 个解决方案

#1


3  

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.

我认为没有直接的财产来实现这一结果。 TextTrimming属性仅适用于TextBlock。最好添加换行符来实现结果。

#2


2  

Just try it with TextAlignment="Justify"

只需使用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."/>

#1


3  

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.

我认为没有直接的财产来实现这一结果。 TextTrimming属性仅适用于TextBlock。最好添加换行符来实现结果。

#2


2  

Just try it with TextAlignment="Justify"

只需使用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."/>