I am working on WPF, i am display RichText data in RichTextBox for that have taken WindowsFormHost, inside that i am taking WinForm RichTextBox to display RichTextData which
You can use BaselineAlignment
on a Run
to center align the text. Here is an example:
<RichTextBox>
<FlowDocument>
<Paragraph>
<Run Text="Some text" BaselineAlignment="Center"/>
<Image Height="100" Width="100" Source="Images\Desert.jpg"/>
<Run Text="Some more text" BaselineAlignment="Center"/>
</Paragraph>
<Paragraph/>
<Paragraph>
<Run Text="Paragraph 2" BaselineAlignment="Center"/>
<Image Height="100" Width="100" Source="Images\Desert.jpg"/>
<Run Text="More text" BaselineAlignment="Center"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
EDIT:
To apply the formatting to the entire RichTextBox
try calling this method after the RichTextBox
is populated:
public void CenterText()
{
var text = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
text.ApplyPropertyValue(Inline.BaselineAlignmentProperty, BaselineAlignment.Center);
}