WPF 文本换行与 WrapWithOverflow

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7348920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 23:04:45  来源:igfitidea点击:

WPF text Wrap vs WrapWithOverflow

wpfword-wrap

提问by Daniele Armanasco

What's the "conceptual" difference between TextWrapping="Wrap"and TextWrapping="WrapWithOverflow"(e.g. for a TextBox)? In the MSDN page about the class TextBox there is nothing ... Thank you.

TextWrapping="Wrap"TextWrapping="WrapWithOverflow"(例如对于文本框)之间的“概念”区别是什么?在有关 TextBox 类的 MSDN 页面中,什么也没有......谢谢。

回答by ken

Some examples:

一些例子:

This is the original, unwrapped version:

这是原始的未包装版本:

No wrapping

无包装



This is NoWrap.

这是NoWrap

NoWrap

无包装



This is Wrap. The words Removeand Samplehave been wrapped at the veand le, respectively, even though there is no line break opportunity.

这是Wrap。即使没有换行机会,单词RemoveandSample也分别被包裹在ve和处le

Wrap

裹



This is WrapWithOverflow. The veand leare not visible (they overflow the available block width) because there is no line break opportunity. The All, in both cases, has been wrapped because the spacecharacter is a line break opportunity.

这是WrapWithOverflow。的vele不可见(溢流出可用块宽度),因为没有换行。的All,在这两种情况下,已进行了换,因为space字符是一个换行。

WrapWithOverflow

WrapWithOverflow



Edit:

编辑:

As suggested in the comments, here's some examples of how Wraptreats spaces. When Widthis 100, Wrapand WrapWithOverfloware identical. Wraptreats the space between widerand exampleas a line-break opportunity, so exampleis put on a new line to preserve the entire, continuous word.

正如评论中所建议的,这里有一些关于如何Wrap处理空格的示例。当Width100WrapWrapWithOverflow是相同的。Wrap治疗之间的空间wider,并example作为一个断行机会,所以example放在一个新行保留整个连续字。

enter image description here

在此处输入图片说明

回答by Arsen Mkrtchyan

MSDN

MSDN

WrapWithOverflowLine-breaking occurs if the line overflows beyond the available block width. However, a line may overflow beyond the block width if the line breaking algorithm cannot determine a line break opportunity, as in the case of a very long word constrained in a fixed-width container with no scrolling allowed.
NoWrapNo line wrapping is performed.
WrapLine-breaking occurs if the line overflows beyond the available block width, even if the standard line breaking algorithm cannot determine any line break opportunity, as in the case of a very long word constrained in a fixed-width container with no scrolling allowed.

WrapWithOverflow如果行溢出超过可用块宽度,则会发生换行。但是,如果换行算法无法确定换行机会,则行可能会溢出超过块宽度,例如在不允许滚动的固定宽度容器中约束非常长的单词的情况下。
NoWrap不执行换行。
行 如果行溢出超过可用块宽度,即使标准换行算法无法确定任何换行机会,也会发生行,就像在固定宽度容器中限制的非常长的单词一样,不允许滚动。

Hope this helps

希望这可以帮助

回答by Vimes

One thing to add to the other answers, WrapWithOverflow lets you use text trimming (ellipsis) on the long words that get cut off:

要添加到其他答案中的一件事,WrapWithOverflow 允许您对被截断的长单词使用文本修剪(省略号):

enter image description here

在此处输入图片说明

<TextBlock TextWrapping="WrapWithOverflow" Width="120" TextTrimming="CharacterEllipsis">
    A really long word is antidisestablishmentarianism and we can use ellipsis trimming.
</TextBlock>