WPF RadRichTextBox - Swapping ENTER key and SHIFT + ENTER Keys Behavior

4 posts, 1 answers
  1. Ramalingam
    Ramalingam avatar
    21 posts
    Member since:
    Apr 2014

    Posted 12 Dec 2014 Link to this post

    Hi Team,
    Please refer to the attachment "Enter key and Shift + Enter keys behavior.png". Please refer to the steps, I followed
    1) Typed "firstline in paragraph1"
    2) Pressed ENTER Key (it creates a new Paragraph)
    3) Typed "second line in paragraph2"
    Actual Result : Pressing ENTER key creates a new paragraph, so we have extra line space
    Expected Result : If we press ENTER key, Can we have next line in same paragraph (without line space)

    4) Typed "para 3 abcd"
    5) Pressed SHIFT key + ENTER key
    6) Typed "efgh"
    Actual Result : Pressing SHIFT key + ENTER key creates a next line in same paragraph.
    Expected Result : If we press SHIFT key + ENTER key, Can we have next line in NEW paragraph

    I have tried the below approaches however no luck.
    void utdRichTextEditor_PreviewEditorKeyDown(object sender, PreviewEditorKeyEventArgs e)
    {
     if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
          &&
          Keyboard.IsKeyDown(Key.Enter))
          {
          e.SuppressDefaultAction = true;
          }
          else if (Keyboard.IsKeyDown(Key.Enter))
          {
          e.SuppressDefaultAction = true;
            ((RadRichTextBox)sender).InsertLineBreak();
          }
    }

    private void SetLineSpacing()
    {
     myRadRichTextBox.Document.LineSpacingType = LineSpacingType.Exact;
     myRadRichTextBox.DocumentInheritsDefaultStyleSettings = true;

     myRadRichTextBox.Document.LineSpacing = 0;
     myRadRichTextBox.Document.ParagraphDefaultSpacingAfter = 0;
     myRadRichTextBox.Document.ParagraphDefaultSpacingBefore = 0;
    }

    Thanks,
    Obuliraj Ramalingam



  2. Tanya
    Admin
    Tanya avatar
    402 posts

    Posted 17 Dec 2014 Link to this post

    Hi Obuliraj,

    SuppressDefaultAction property stops the default action that needs to be executed, but PreviewEditorKeyDown is a tunneling event. In other words, its route direction travels from the application root towards the element that raised the event. To stop this travelling when the event is handled in the code, you can use the OriginalArgs.Handled property of PreviewEditorKeyEventArgs. For more clarity, please, refer to the snippet below. It is modified to use the mentioned property.
    private void radRichTextBox_PreviewEditorKeyDown(object sender, PreviewEditorKeyEventArgs e)
    {
        if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
            && Keyboard.IsKeyDown(Key.Enter))
        {
            e.SuppressDefaultAction = true;
            e.OriginalArgs.Handled = true;
            (sender as RadRichTextBox).InsertParagraph();
        }
        else if (Keyboard.IsKeyDown(Key.Enter))
        {
            e.SuppressDefaultAction = true;
            e.OriginalArgs.Handled = true;
            (sender as RadRichTextBox).InsertLineBreak();
        }
    }
    Please, let me know if you have any other questions.

    Regards,
    Tanya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ramalingam
    Ramalingam avatar
    21 posts
    Member since:
    Apr 2014

    Posted 17 Dec 2014 in reply to Tanya Link to this post

    Hi Tanya,
    Thanks for the sample code.
    I think "InsertParagraph()" method is not available for RadRichTextBox.
    Could you please suggest a way to insert a new Paragraph

    Thanks,
    Obuliraj Ramalingam
  5. Answer
    Tanya
    Admin
    Tanya avatar
    402 posts

    Posted 18 Dec 2014 Link to this post

    Hello Obuliraj,

    The InsertParagraph() method is introduced with our Q2 2014 release in Service Pack 1. You can update your version of the suite in order to have all introduced features and fixes or replace the method with formatting symbol insertion:
    this.radRichTextBox.Insert(FormattingSymbolLayoutBox.ENTER);

    Please note that in the next version of the control we will introduce a change concerning the FormattingSymbolLayoutBox class. For now, the above code breaks the current paragraph, but after the change it will simply insert the paragraph end symbol. 

    Hope this helps.

    Regards,
    Tanya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top