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

shift+enter and focus

5 Answers 73 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Oren
Top achievements
Rank 1
Oren asked on 29 Jan 2014, 03:35 PM
Hello,
I have a regular Datagrid (not telerik's) that contains a "DataGridTemplateColumn".
The template of the column is a "RadRichTextBox" with a "TxtDataProvider" that is bound to my ViewModel.

my questions are:

1)
Is there a way to cancel the shift+enter?
Or alternatively control the spacing of the new paragraph (that was created with the "Enter" key), So that it seem like a single line brake, instead of a double line?
I tried the folowing:
private void TxtDataProvider_SetupDocument(object sender, Telerik.Windows.Documents.FormatProviders.SetupDocumentEventArgs e)
{
    e.Document.LineSpacing = 0;
}

And it  works great for the "Enter", however the "Shift+Enter" just write in the same line(overrides the same line visually).

and 2)
If i replace the "RadRichTextbox" with a regular textbox i can move through the grid with the arrow keys.
However in the case of the  "RadRichTextBox" it doesn't work, the "RadRichTextBox" keeps the focus and the Selected Row doesn't change.
Is there a way to overcome this behavior?

Thank you
Oren

5 Answers, 1 is accepted

Sort by
0
Missing User
answered on 03 Feb 2014, 11:23 AM
Hi Oren,

Thank you for contacting us!

If you are going to control the spacing of a new paragraph, I would recommend you not to use “e.Document.LineSpacing = 0” because it may cause many serious problems to your document. Instead of it, you could easy the default spacing before and after a paragraph as it is shown in the following code-snippet:
this.editor.Document.ParagraphDefaultSpacingAfter = 0;
this.editor.Document.ParagraphDefaultSpacingBefore = 0;

As to the “Shift+Enter” key combination, if your desire is to cancel its default behavior, you could accomplish this with few lines of code in XAML. The code-snippet below explains it:
<telerik:RadRichTextBox Name="editor" LayoutMode="Paged">
    <telerik:RadRichTextBox.InputBindings>
        <KeyBinding Gesture="Shift+Enter"></KeyBinding>
    </telerik:RadRichTextBox.InputBindings>
</telerik:RadRichTextBox>
Please take a look at this article regarding more information about Keyboard Support. 

Implementing the behavior described in you second question is possible to be achieved. I've attached a small running example to illustrate to you how to move through the grid with the arrows like in your desired scenario.

I hope this helps.
I would be happy to provide any further assistance. Please, do not hesitate to ask any questions!

Regards,
Yancho
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Oren
Top achievements
Rank 1
answered on 03 Feb 2014, 03:21 PM
Hi Yancho,
Thank you for the reply
i have some follow up questions:

1)
the "ParagraphDefaultSpacingAfter" did fixed my problem but in your second suggestion, the "telerik:RadRichTextBox.InputBindings" throws a compilation error of "not Recognize".
Am i missing a reference?

2)
Your solution works perfectly for a low amount of items, however if you try adding more items to your "ExampleDataContext" the "dataGrid.ChildrenOfType" will return only the items that are shown right now in the grid, I believe this is a virtualization problem,
Is there a way to fix this?

Thanks again
Oren
0
Missing User
answered on 05 Feb 2014, 09:17 AM
Hi Oren,

The virtualization helps to increase the performance of the Telerik RadRichTextBox. Please be aware that if you are going to remove the virtualization from the DataGrid, you would experience great performance loss. For example, even only ten RadRichTextBoxes could slow down greatly the work of your project.

A possible solution to your problem could be to check whether the focus is on the last/first RadRichTextBox. If it is, you could scroll down/up a little bit and show another element. This way you would have the ability to move the focus on it.

About the thrown compilation error, the code in the codes-snippet which I gave you is for the WPF version of the control. Please excuse me for this lapse! The right syntax for Silverlight is the following one: 
<telerik:RadRichTextBox x:Name="radRichTextBox" Grid.Row="1">
    <telerik:CommandManager.InputBindings>
        <telerik:InputBindingCollection>
            <telerik:KeyBinding Gesture="Shift+Enter" />
        </telerik:InputBindingCollection>
    </telerik:CommandManager.InputBindings>
</telerik:RadRichTextBox>

Let me know if you have other comments or questions.

Regards,
Yancho
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Oren
Top achievements
Rank 1
answered on 05 Feb 2014, 10:29 AM
Thank you very much!
It works perfectly now.

This is my working code for the focus issue, if you are interested:
if (e.Command is MoveCaretCommand)
{
    var parameter = e.CommandParameter.ToString();
 
    if (parameter == "Down" || parameter == "Up")
    {
        e.Cancel = true;
 
        switch (e.CommandParameter.ToString())
        {
            case "Down":
                this.dataGrid.SelectedIndex++;
                break;
            case "Up":
                this.dataGrid.SelectedIndex--;
                break;
        }
        dataGrid.BeginEdit();
        dataGrid.UpdateLayout();
        dataGrid.ScrollIntoView(dataGrid.SelectedItem, dataGrid.Columns[0]);
    }
}


Thank you.
Oren
0
Missing User
answered on 05 Feb 2014, 12:00 PM
Hi Oren,

Thank you for your contribution to our forum community.

I hope that your code would be helpful to other users who would try to implement such functionality.

Regards,
Yancho
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
RichTextBox
Asked by
Oren
Top achievements
Rank 1
Answers by
Missing User
Oren
Top achievements
Rank 1
Share this question
or