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

Read Only Span

7 Answers 166 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
jbaird
Top achievements
Rank 1
jbaird asked on 22 Aug 2011, 06:56 PM
I am inserting a custom span into the editor so I can have a number of custom attributes defined and stored.  It looks like a hyperlink, but it is a different color, i.e. <My custom data point>.  I need this content between the "<" and the ">" to be read only.  I think it could be done by forcing the caret back to the beginning if it lands in one of my custom spans.... however, you said something about read0nly regions for the new release.  Is that something I can leverage for this ?  If not, what is the best way to prevent editing of a custom data point like this?

7 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 25 Aug 2011, 09:59 AM
Hello Jbaird,

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 >>

0
Dustin
Top achievements
Rank 1
answered on 09 Sep 2011, 04:05 PM
I see that the RadDocument has a method ".InsertReadOnlyRange(DocumentPosition start, DocumentPosition end)"

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?
0
Iva Toteva
Telerik team
answered on 14 Sep 2011, 06:35 PM
Hello Dustin,

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 >>

0
Robert
Top achievements
Rank 1
answered on 15 Feb 2012, 01:30 PM
Hi,

Does this also apply to WPF RadDocument?
0
Iva Toteva
Telerik team
answered on 16 Feb 2012, 09:24 PM
Hi Robert,

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.

All the best,
Iva Toteva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Robert
Top achievements
Rank 1
answered on 17 Feb 2012, 02:30 AM
Thank you very much for your response. The read only range works well.
<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.
0
Ivailo Karamanolev
Telerik team
answered on 20 Feb 2012, 12:41 PM
Hello,

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
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
RichTextBox
Asked by
jbaird
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Dustin
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Ivailo Karamanolev
Telerik team
Share this question
or