Block.TextAlignment Property

Definition

Gets or sets the horizontal alignment of text content.

C#
public System.Windows.TextAlignment TextAlignment { get; set; }

Property Value

One of the TextAlignment values that specifies the desired alignment. The default is Left.

Examples

The following example shows how to set the TextAlignment attribute of a Block element.

XAML
<FlowDocument>
  <Paragraph Background="GhostWhite" TextAlignment="Center">
    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>

The following figure shows how the preceding example renders with Left text alignment (the default).

Screenshot: TextAlign property value of Left

The following figure shows how the same example renders with Right text alignment.

Screenshot: TextAlign value of Right

The following figure shows how the same example renders with Center text alignment.

Screenshot: TextAlign property value of Center

The following example shows how to set the TextAlignment property programmatically.

C#
Paragraph par = new Paragraph();
par.TextAlignment = TextAlignment.Center;

Remarks

Dependency Property Information

Item Value
Identifier field TextAlignmentProperty
Metadata properties set to true AffectsMeasure, AffectsRender, Inherits

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9