Reputation: 1127
How to change the vertical and horizontal alignment of RichText box. i have tried all the api's horizontalalignment and vertical alignment. but nothing works.
Upvotes: 4
Views: 4283
Reputation: 1542
What you are looking for are called EditingCommands
EditingCommands.AlignLeft.Execute(null, richTextBox);
//or
EditingCommands.AlignRight.Execute(null, richTextBox);
You can find all kinds of text editing commands here.
Upvotes: 0
Reputation: 6648
For horizontal alignment of RichTextBox, you could change it by FlowDocument
's property TextAlignment
.
Example:
<RichTextBox x:Name="richTextBox" Height="30" >
<FlowDocument TextAlignment="Center">
<Paragraph>
<Run Text="RichTextBox"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
Upvotes: 4
Reputation: 33
This property returns the current alignment. Setting this property adjusts the contents of the RichTextBox to reflect the specified alignment.
<!--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;
}
Upvotes: 3