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>"
???
4 Answers, 1 is accepted
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;
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.
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!!!!
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.
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
But after saving text and reading it line breaks appears again.
Can you advice solution for that behaviour?