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

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

3 Answers 553 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Ramalingam
Top achievements
Rank 1
Ramalingam asked on 12 Dec 2014, 11:32 AM
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



3 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 17 Dec 2014, 11:55 AM
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.

 
0
Ramalingam
Top achievements
Rank 1
answered on 17 Dec 2014, 12:14 PM
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
0
Accepted
Tanya
Telerik team
answered on 18 Dec 2014, 04:17 PM
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.

 
Tags
RichTextBox
Asked by
Ramalingam
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Ramalingam
Top achievements
Rank 1
Share this question
or