TextBlock.LineStackingStrategy 属性

定义

获取或设置用于为 TextBlock 中的每行文本确定行框的机制。Gets or sets the mechanism by which a line box is determined for each line of text within the TextBlock.

public:
 property System::Windows::LineStackingStrategy LineStackingStrategy { System::Windows::LineStackingStrategy get(); void set(System::Windows::LineStackingStrategy value); };
public System.Windows.LineStackingStrategy LineStackingStrategy { get; set; }
member this.LineStackingStrategy : System.Windows.LineStackingStrategy with get, set
Public Property LineStackingStrategy As LineStackingStrategy

属性值

用于为 TextBlock 中的每行文本确定行框的机制。The mechanism by which a line box is determined for each line of text within the TextBlock. 默认值为 MaxHeightThe default is MaxHeight.

示例

下面的示例演示如何使用 LineStackingStrategy 属性来确定如何为 TextBlock的文本行创建行框。The following example shows how to use the LineStackingStrategy property to determine how the line boxes are created for text lines of a TextBlock. 第一个 TextBlockLineStackingStrategy 值为 MaxHeight,第二个 TextBlock 的值为 BlockLineHeightThe first TextBlock has a LineStackingStrategy value of MaxHeight and the second TextBlock has a value of BlockLineHeight.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <StackPanel>
    
    <!-- This TextBlock has a LineStackingStrategy set to "MaxHeight". -->
    <TextBlock LineStackingStrategy="MaxHeight" LineHeight="10" Width="500" TextWrapping="Wrap" 
     Background="Yellow">
      Use the <Span FontSize="30">LineStackingStrategy</Span> property to determine how a line box is
      created for each line. A value of <Span FontSize="20">MaxHeight</Span> 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 <Span FontSize="20">BlockLineHeight</Span> specifies
      that the stack height is determined by the block element LineHeight property value.
    </TextBlock>

    <!-- Here is the same TextBlock but the LineStackingStrategy is set to "BlockLineHeight". -->
    <TextBlock LineStackingStrategy="BlockLineHeight" LineHeight="10" Width="500" TextWrapping="Wrap" 
     Background="Blue" Margin="0,40,0,0">
      Use the <Span FontSize="30">LineStackingStrategy</Span> property to determine how a line box is
      created for each line. A value of <Span FontSize="20">MaxHeight</Span> 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 <Span FontSize="20">BlockLineHeight</Span> specifies
      that the stack height is determined by the block element LineHeight property value.
    </TextBlock>

  </StackPanel>
</Page>

下图显示了前面的代码的结果。The following illustration shows the result of the preceding code.

Screenshot:比较 LineStackingStrategy 值Screenshot: Compare LineStackingStrategy values

注解

此依赖属性还具有附加的属性用法。This dependency property also has an attached property usage. XAMLXAML中,使用情况是 <object TextBlock.LineStackingStrategy="value".../>的,其中object是包含在 TextBlock内的对象元素(通常是 flow 元素),LineStackingStrategy 枚举的字符串值。In XAMLXAML, the usage is <object TextBlock.LineStackingStrategy="value".../>, where object is an object element (typically a flow element) contained within a TextBlock, and value is a string value of the LineStackingStrategy enumeration. 在代码中,GetLineStackingStrategySetLineStackingStrategy支持附加的属性用法。In code, the attached property usage is supported by GetLineStackingStrategy and SetLineStackingStrategy. 附加的属性用法并不常见。The attached property usage is not common.

依赖项属性信息Dependency Property Information

标识符字段Identifier field LineStackingStrategyProperty
元数据属性设置为 trueMetadata properties set to true AffectsMeasureAffectsRenderAffectsMeasure, AffectsRender

适用于