RichTextBox.TextAlignment Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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


Public Property TextAlignment As TextAlignment
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.

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 Sub button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim MyBC As BlockCollection = InlineAssignHelper(MyBC, MyRTB.Blocks)
    For Each b As Block In MyBC
        b.TextAlignment = TextAlignment.Right
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
    target = value
    Return value
End Function
//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;               

Version Information


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.