Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TextBlock.LineStackingStrategy Property

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)

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.

Dependency property identifier field: LineStackingStrategyProperty

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.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

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

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

Community Additions

Show:
© 2014 Microsoft