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
WPF text Wrap vs WrapWithOverflow
提问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:
这是原始的未包装版本:
This is NoWrap
.
这是NoWrap
。
This is Wrap
. The words Remove
and Sample
have been wrapped at the ve
and le
, respectively, even though there is no line break opportunity.
这是Wrap
。即使没有换行机会,单词Remove
andSample
也分别被包裹在ve
和处le
。
This is WrapWithOverflow
. The ve
and le
are 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 space
character is a line break opportunity.
这是WrapWithOverflow
。的ve
和le
不可见(溢流出可用块宽度),因为没有换行。的All
,在这两种情况下,已进行了换,因为space
字符是一个换行。
Edit:
编辑:
As suggested in the comments, here's some examples of how Wrap
treats spaces. When Width
is 100
, Wrap
and WrapWithOverflow
are identical. Wrap
treats the space between wider
and example
as a line-break opportunity, so example
is put on a new line to preserve the entire, continuous word.
正如评论中所建议的,这里有一些关于如何Wrap
处理空格的示例。当Width
是100
,Wrap
和WrapWithOverflow
是相同的。Wrap
治疗之间的空间wider
,并example
作为一个断行机会,所以example
放在一个新行保留整个连续字。
回答by Arsen Mkrtchyan
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 允许您对被截断的长单词使用文本修剪(省略号):
<TextBlock TextWrapping="WrapWithOverflow" Width="120" TextTrimming="CharacterEllipsis">
A really long word is antidisestablishmentarianism and we can use ellipsis trimming.
</TextBlock>