Enter Key Behavior

5 posts, 0 answers
  1. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 19 Apr 2013 Link to this post

    I have a radrichtextbox that no matter what I do I can't get it to single space when hitting the enter key.

    I'm explicitly setting the following when initializing the control, and then again on the SetupDocument event
    Document.ParagraphDefaultSpacingAfter = 0;
    Document.ParagraphDefaultSpacingBefore = 0;
    Document.LineSpacing = 1;

    Inspecting these properties afterwards shows that they are set to values above, but the enter key still does a double space.  I want enter to equal a "return" not "<p>"

    ???
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 22 Apr 2013 Link to this post

    Hello,

    The ParagraphDefaultSpacingBefore property is 0 by default and LineSpacing is responsible for the space between lines in the same paragraph, so you do not need to set them in order to achieve the wanted behavior. However, I am not sure why you are unable to change the spacing after, as putting this code:
    this.editor.Document.ParagraphDefaultSpacingAfter = 0;
    in the constructor of the page and in the DocumentChanged event handler results in the needed behavior on our end as you can verify from the attached picture.

    On the other hand, this does not change the structure of the document and each time you press Enter, that will result in a new paragraph and not a line break (or return). What you can do in this regard is subscribe to the PreviewEditorKeyDown event of RadRichTextBox and suppress the default action like this:
    void editor_PreviewEditorKeyDown(object sender, Telerik.Windows.Documents.PreviewEditorKeyEventArgs e)
    {
        if(e.Key == Key.Enter)
        {
            e.SuppressDefaultAction = true;
            e.OriginalArgs.Handled = true;
            (sender as RadRichTextBox).Insert(FormattingSymbolLayoutBox.LINE_BREAK);
        }         
    }

    When pressing Enter, the space will be equal to the one between lines in the same paragraph and the document will not break into separate paragraphs. You can refer to the attached image for a reference.

    Please not that it is not recomended to create large paragraphs in RadDocument for performance purposes.

    I hope the provided information is helpful! Let us know if you have other questions.
     
    Regards,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 22 Apr 2013 Link to this post

    Thanks Petya, I will give that a try.  

    Another question I have is, Can you have more than one data provider for a RadRichTextBox?  Our challenge is that the source of the document can be plain text, or it can be html.  I'm working on trying to implement this, but you may be able to point to an article or something that shows how to do this.  I looked through the demos and the online documentation and I didn't see anything dealing with this specific issue.

    Thanks again for your help!!!!
  5. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 25 Apr 2013 Link to this post

    Hi,

    In general, you can have two data providers bound to RadRichTextBox, but that will create additional overhead in the case of two-way databinding. Then, on every change in the document, it would need to be exported twice.

    You could try using HtmlFormatProvider and TxtFormatProvider instead of the respective DataProviders and update the strings and the document on demand. You could encapsulate this logic in a CustomDataProvider that sometimes uses HtmlFormatProvider and sometimes TxtFormatProvider.

    The use of the format providers is illustrated here, while you can also download the source of the controls to see how the DataProviders have been implemented for reference.

    Kind regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Alex Olenev
    Alex Olenev avatar
    9 posts
    Member since:
    Oct 2009

    Posted 25 Oct 2013 Link to this post

    That works well while editing.

    But after saving text and reading it line breaks appears again.
    Can you advice solution for that behaviour?
Back to Top
DevCraft banner