FlowDocument.TextAlignment 属性

定义

获取或设置一个值,该值指示文本内容的水平对齐方式。

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

属性值

TextAlignment 值之一,它指定所需的对齐方式。 默认值为 Left

示例

以下示例演示如何设置 TextAlignment 元素的 FlowDocument 属性。

<FlowDocumentReader>
  <FlowDocument
    TextAlignment="Center"
>
    <Paragraph Background="GhostWhite">
      One<LineBreak/>
      two two<LineBreak/>
      Three Three Three<LineBreak/>
      four four four four<LineBreak/>
      Five Five Five Five Five<LineBreak/>
      six six six six six six<LineBreak/>
      Seven Seven Seven Seven Seven Seven Seven<LineBreak/>
      eight eight eight eight eight eight eight eight
    </Paragraph>
  </FlowDocument>
</FlowDocumentReader>

下图显示了前面的 FlowDocument 呈现方式与 Left 文本对齐方式 (默认) 。

屏幕截图:Left 的 TextAlign 属性值

下图显示了相同 FlowDocument 文本对齐方式的 Right 呈现方式。

屏幕截图:右侧的 TextAlign 值

下图显示了相同 FlowDocument 文本对齐方式的 Center 呈现方式。

屏幕截图:Center 的 TextAlign 属性值

下面的示例演示如何以编程方式设置 TextAlignment 属性。

FlowDocument flowDoc = new FlowDocument(new Paragraph(new Run("A bit of text content...")));

// Text will be centered.
flowDoc.TextAlignment = TextAlignment.Center;
Dim flowDoc As New FlowDocument(New Paragraph(New Run("A bit of text content...")))

' Text will be centered.
flowDoc.TextAlignment = TextAlignment.Center

注解

依赖项属性信息

标识符字段 TextAlignmentProperty
元数据属性设置为 true AffectsMeasure, AffectsRender, Inherits

适用于