7 Answers, 1 is accepted
We introduced read-only regions in the Q2 2011 version. The feature is not well documented and is not publicly announced, as it it not fully implemented (export/import works only with the native XAML format). Read-only regions can be created from the selection with the following line:
this
.radRichTextBox.InsertReadOnlyRange();
You can also create a document in code-behind and mark the read-only part of the document with ReadOnlyRegionStart and ReadOnlyRegionEnd inlines. If you chose this path for your development, we'll be glad to assist you with any specific questions you might have. All the best,
Iva
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
My only question though is how can I capture the start position and the end position of my range. Whenever I create a DocumentPosition variable, the position always changes and when i create an end DocumentPosition variable its only in sync with the start DocumentPosition.
Can someone please explain how to properly capture the start and end DocumentPosition range?
You can read more about DocumentPositions here. The Search article also shows how document positions can be used in order to find and replace some words in a document.
Here is an example:
private
void
MarkCurrentParagraphReadOnly()
{
DocumentPosition start =
this
.GetStartOfCurrentDocumentElement(
this
.editor.Document.CaretPosition.GetCurrentInlineBox());
DocumentPosition end =
new
DocumentPosition(start);
start.MoveToFirstPositionInParagraph();
end.MoveToLastPositionInParagraph();
this
.editor.Document.InsertReadOnlyRange(start, end);
}
private
DocumentPosition GetStartOfCurrentDocumentElement(InlineLayoutBox layoutBox)
{
DocumentPosition position =
new
DocumentPosition(
this
.editor.Document);
position.MoveToInline(layoutBox, 0);
return
position;
}
Another option would be to use the method InsertReadOnlyRange from RadRichTextBox's API which operates on the selection. More info on selection can be found here.
Kind regards,
Iva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Does this also apply to WPF RadDocument?
Yes, the same methods could be used in the WPF version of RadDocument/RadRichTextBox.
You can also use PermissionRanges, previewed and explained in this online demo (the demo is also available for WPF within the installation package).
The difference is that with permission ranges, most of the document is ReadOnly and you can edit only certain parts of the document. With ReadOnlyRanges, it is the other way around.
When it comes to import and export, protected regions can be saved in docx and XAML while ReadOnlyRanges are persisted only in XAML.
Iva Toteva
the Telerik team
<
t:Paragraph
>
<
t:ReadOnlyRangeStart
/>
<
t:Span
Text
=
"Bedroom 1"
FontFamily
=
"Calibri"
FontSize
=
"20"
ForeColor
=
"SteelBlue"
></
t:Span
>
<
t:ReadOnlyRangeEnd
/>
</
t:Paragraph
>
One more question. As above, I am able to make a range readonly. Is it possible to make an entire line readonly so that you cannot align other text next to it?
For example, this situation might be used for a heading scenario. I want a heading to be readonly then editable text will have to reside on the lines below the heading.
Thank you for your time.
Currently we haven't planned functionality like the one you mentioned. The best workaround you can implement is to place the ReadOnlyRangeEnd in the beginning of the next paragraph, so that the heading will remain on the line it is. Another option would be to utilize document protection and add permission where you want the user to be able to edit. You can try both approaches and decide which one best fits your requirements.
Let us know if we can assist you further.
Kind regards,
Ivailo Karamanolev
the Telerik team