Condividi tramite


TextBlock.LineStackingStrategy Property

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

Gets or sets a value that indicates how a line box is determined for each line of text in the TextBlock.

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

Syntax

'Declaration
Public Property LineStackingStrategy As LineStackingStrategy
public LineStackingStrategy LineStackingStrategy { get; set; }
<TextBlock LineStackingStrategy="BlockLineHeight"/>
-or-
<TextBlock LineStackingStrategy="MaxHeight"/>

Property Value

Type: System.Windows.LineStackingStrategy
A value that indicates how a line box is determined for each line of text in the TextBlock. The default is LineStackingStrategy.MaxHeight.

Remarks

Dependency property identifier field: LineStackingStrategyProperty

Examples

The following example shows how to use the LineStackingStrategy property to determine how the line boxes are created for text lines of a TextBlock. The first TextBlock has a LineStackingStrategy value of MaxHeight and the second TextBlock has a value of BlockLineHeight.

<StackPanel>

<!-- This TextBlock has a LineStackingStrategy set to "MaxHeight". -->
<TextBlock    FontFamily="Verdana"
                    LineStackingStrategy="MaxHeight" 
                    LineHeight="10" 
                    Width="500" 
                    TextWrapping="Wrap" >
    Use the <Run FontSize="30">LineStackingStrategy</Run> property to determine how a line box is
    created for each line. A value of <Run FontSize="20">MaxHeight</Run> specifies that the stack
    height is the smallest value that contains all the inline elements on that line when those
    elements are properly aligned. A value of <Run FontSize="20">BlockLineHeight</Run> specifies
    that the stack height is determined by the block element LineHeight property value.
</TextBlock>

    <!-- With a margin pushing down 20 pixels, draw a line just above the second textblock. -->
    <!-- The fonts will reach above the LineHeight size and over the line. -->
<StackPanel Margin="0,20,0,0" HorizontalAlignment="Center">
    <Line Stroke="Green"  X2="500" />
</StackPanel>

            <!-- Here is the same TextBlock but the LineStackingStrategy is set to "BlockLineHeight". -->
<TextBlock    FontFamily="Verdana"
                    LineStackingStrategy="BlockLineHeight" 
                    LineHeight="10" 
                    Width="500" 
                    TextWrapping="Wrap">
    Use the <Run FontSize="30">LineStackingStrategy</Run> property to determine how a line box is
    created for each line. A value of <Run FontSize="20">MaxHeight</Run> specifies that the stack
    height is the smallest value that contains all the inline elements on that line when those
    elements are properly aligned. A value of <Run FontSize="20">BlockLineHeight</Run> specifies
    that the stack height is determined by the block element LineHeight property value.
</TextBlock>

</StackPanel>

The following illustration shows the result of the preceding code.

LineStackingStrategy determining line heights.

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.