开发者

WPF text Wrap vs WrapWithOverflow

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 nothin开发者_如何学Gog ... Thank you.


Some examples:

This is the original, unwrapped version:

WPF text Wrap vs WrapWithOverflow


This is NoWrap.

WPF text Wrap vs WrapWithOverflow


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.

WPF text Wrap vs WrapWithOverflow


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.

WPF text Wrap vs WrapWithOverflow


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.

WPF text Wrap vs WrapWithOverflow


MSDN

WrapWithOverflow Line-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.
NoWrap No line wrapping is performed.
Wrap Line-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.


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

WPF text Wrap vs WrapWithOverflow

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜