This is a migrated thread and some comments may be shown as answers.

Telerik WPF RichTextBox

1 Answer 189 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Cristiano
Top achievements
Rank 1
Cristiano asked on 05 Sep 2014, 10:44 AM
Hi, 

I'm working with the RichTextBox control and I need to change the default alignment of text to justified. How can I do this? 
Did some testing, but without success.

Here is the code i am using:

 public void SetRichTextBoxSettings(ObservableCollection<Examination> examinations)
{           
       RichTextBox.HorizontalAlignment = HorizontalAlignment.Stretch; 
      //foreach (var paragraph in RichTextBox.Document.EnumerateChildrenOfType<Paragraph>())
      //{
            //paragraph.TextAlignment = RadTextAlignment.Justify;
       //}
       RichTextBox.DocumentInheritsDefaultStyleSettings = true;
}

Any help would be appreciated.

Best regards,
Cristiano Machado









1 Answer, 1 is accepted

Sort by
0
Aylin
Telerik team
answered on 10 Sep 2014, 10:18 AM
Hi Cristiano,

The desired alignment could be achieved by setting the TextAlignment property of the paragraph to RadTextAlignment.Justify, just as you have done in the commented part in your example code.

paragraph.TextAlignment = RadTextAlignment.Justify;

That alignment will be applied for each newly added paragraph after the one you've set the property to.

In case you need to align the text in an existing document, you need to select the whole document, apply the alignment and then eventually clear the selection. Here is the code snippet for this:

this.radRichTextBox.Document.Selection.SelectAll();
this.radRichTextBox.ChangeTextAlignment(RadTextAlignment.Justify);
this.radRichTextBox.Document.Selection.Clear();

Setting RichTextBox.HorizontalAlignment property to HorizontalAlignment.Stretch is not recommended as it could lead to issues with the formatting.

I hope this helps.

Regards,
Aylin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
RichTextBox
Asked by
Cristiano
Top achievements
Rank 1
Answers by
Aylin
Telerik team
Share this question
or