Поделиться через


TextBlock.TextWrapping Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets how the TextBlock wraps text.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property TextWrapping As TextWrapping
public TextWrapping TextWrapping { get; set; }
<TextBlock TextWrapping="Wrap"/>

Property Value

Type: System.Windows.TextWrapping
A value that indicates how the TextBlock wraps text. The default is TextWrapping.NoWrap.

Remarks

Dependency property identifier field: TextWrappingProperty

The TextWrapping property indicates how text wraps in a TextBlock. The TextWrapping enumeration defines two values: NoWrap and Wrap.

NoteNote:

In Silverlight, this property does not support a WrapWithOverflow value.

ActualHeight and ActualWidth are read-only properties that report the rendered height and width of the TextBlock. These properties can be different than the Height and Width properties of the TextBlock. Setting the TextWrapping property affects the ActualHeight and ActualWidth values of the TextBlock.

The following illustration shows how the TextWrapping property affects ActualHeight and ActualWidth.

How TextWrapping affects ActualWidth and ActualHeight

TextWrapping example.

Examples

The following XAML example shows how to set the TextWrapping property to NoWrap and to Wrap.

<!-- TextBlock with no text wrapping -->
<TextBlock
  Text="The quick red fox jumped over the lazy brown dog."
  Width="200"
  TextWrapping="NoWrap" />

<!-- TextBlock with text wrapping -->
<TextBlock
  Text="The quick red fox jumped over the lazy brown dog."
  Width="200"
  TextWrapping="Wrap" />

The following illustration shows the rendered text from the previous XAML example.

TextBlock rendering non-wrapped and wrapped text

Shows text getting cut off.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.