Read Only Span

8 posts, 0 answers
  1. jbaird
    jbaird avatar
    19 posts
    Member since:
    Jul 2012

    Posted 22 Aug 2011 Link to this post

    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?

  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 25 Aug 2011 Link to this post

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

  3. DevCraft banner
  4. Dustin
    Dustin avatar
    79 posts
    Member since:
    Oct 2012

    Posted 09 Sep 2011 Link to this post

    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?
  5. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 14 Sep 2011 Link to this post

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

  6. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 15 Feb 2012 Link to this post

    Hi,

    Does this also apply to WPF RadDocument?
  7. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 16 Feb 2012 Link to this post

    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 >>
  8. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 16 Feb 2012 Link to this post

    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.
  9. Ivailo Karamanolev
    Admin
    Ivailo Karamanolev avatar
    276 posts

    Posted 20 Feb 2012 Link to this post

    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 >>
Back to Top
DevCraft banner