Telerik WPF RichTextBox

2 posts, 0 answers
  1. Cristiano
    Cristiano avatar
    13 posts
    Member since:
    Feb 2012

    Posted 05 Sep 2014 Link to this post


    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

  2. Aylin
    Aylin avatar
    75 posts

    Posted 10 Sep 2014 Link to this post

    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:


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

    I hope this helps.

    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.
Back to Top