TextAlignment Property

RichTextBox.TextAlignment Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets how the text should be aligned in the RichTextBox.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public TextAlignment TextAlignment { get; set; }
<RichTextBox TextAlignment="textAlignmentValue"/>

XAML Values

textAlignmentValue

A named constant of the TextAlignment enumeration, such as Left.

Property Value

Type: System.Windows.TextAlignment
One of the TextAlignment enumeration values. The default is Left.

This property returns the current alignment. Setting this property adjusts the contents of the RichTextBox to reflect the specified alignment.

The following example shows how you can right-align the entire contents of the RichTextBox.


<!--Create a RichTextBox and a Button.-->
<StackPanel>
    <RichTextBox x:Name="MyRTB" Height="100" Width="400" />
    <Button x:Name="MyButton1" Content="Right-Align" Height="30" Width="100" Click="button_Click" />
</StackPanel>



//Right-align the content in RichTextBox on clicking the button.
private void button_Click(object sender, RoutedEventArgs e)
{
   BlockCollection MyBC = MyRTB.Blocks;
   foreach (Block b in MyBC)
       b.TextAlignment = TextAlignment.Right;               
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2017 Microsoft