194

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.

Callum Watkins
  • 2,844
  • 4
  • 29
  • 49
Daniele Armanasco
  • 7,289
  • 9
  • 43
  • 55

3 Answers3

368

Some examples:

This is the original, unwrapped version:

No wrapping


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


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


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.

enter image description here

qxn
  • 17,162
  • 3
  • 49
  • 72
  • 6
    This answer would benefit from including one more (wider) button example in each mode that does have a valid whitespace break. At a glance, it implies that `Wrap` completely ignores whitespace breaks, but that isn't true. – Scott Stafford Apr 07 '15 at 20:39
204

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.

starball
  • 20,030
  • 7
  • 43
  • 238
Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184
  • 11
    I know this question was directed at WPF, but I thought it might be worth noting that `WrapWithOverflow` is not supported in Silverlight. Only `Wrap` and `NoWrap` are supported in Silverlight. http://msdn.microsoft.com/en-us/library/system.windows.textwrapping(v=vs.95).aspx – blachniet Aug 26 '12 at 00:17
  • 5
    I read this and am still not certain of the difference. Is the basic idea that `WrapWithOverFlow` will not break words, but `Wrap` will? – Brian J Jun 19 '13 at 19:44
  • 7
    @BrianJ - See my answer for some examples. – qxn Jul 31 '13 at 21:21
17

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

enter image description here

<TextBlock TextWrapping="WrapWithOverflow" Width="120" TextTrimming="CharacterEllipsis">
    A really long word is antidisestablishmentarianism and we can use ellipsis trimming.
</TextBlock>
Vimes
  • 10,577
  • 17
  • 66
  • 86