RichTextBox.TextAlignment Property


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

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

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

XAML Values


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.

Run this sample

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

//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;               


Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

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