9 Answers, 1 is accepted
In order to replace the content of a bookmark with some text you can use the following method:
where bookmarksToContent is a Dictionary<string, string> mapping bookmark names to some other content. In this way, the bookmarks themselves will be removed from the document.
If you want to preserve them, just change the text between the BookmarkRangeStart and BookmarkRangeEnd document elements, you can do so like this:
More information on Bookmarks, BookmarkRangeStart and BookmarkRangeEnd can be found in our online documentation.
However, if you are using bookmarks in order to implement Mail Merge, this is no longer necessary, because RadRichTextBox supports merge fields and merge out of the box.
I hope this helps.
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
I'm want to insert a document fragment between the BookmarkRangeStart and BookmarkRangeEnd document elements, and try to use your code example, but it is not working for me.
In order to insert plain text I have to modify your code slightly to also define start position.
This will produce the document structure I want (xaml):
However when I try to insert a document fragment the fragment is placed below the bookmark end:
results in the document (xaml)
How can I insert the fragment text between the BookmarkRange tags??
However, it seems that there is some bug with the insertion of the BookmarkRangeStart if the first already existing element in the paragraph is a bookmark, then the inserted bookmark range is placed after the existing bookmark. Is this a known issue? Maybe it is a problem with the xaml format provider?
When selecting tha content of a bookmark range, and then extracting tha content to either a DocumentFragment or a RadDocument, the bookmarks within the content are removed.
I have a rad document (shorted for brevity):
I select content of the OrderList Bookmark range
This will produce the following fragment/document
So the bookmark ranges inside the selection are removed,
How can I preserve them when copying the selection??
The issue you explained in your first post seems related to a known bug in the RadDocument.InsertFragment(Document Fragment fragment, DocumentPosition position) method. What you can do in order to avoid it is to use the other method for inserting a fragment instead - RadDocument.InsertFragment(DocumentFragment fragment) which inserts the fragment at the caret location, so you should move the caret to the wanted position prior invoking it.
I am not exactly sure what causes the problem described in your second post, but from the looks of the document in your last post, you've managed to solve it.
As for the behavior when copying text containing bookmarks, the result you are observing is the one by design. All DocumentElements have a IsCopyable bool property and it is set to false for BookmarkRangeStart and BookmarkRangeEnd. The reason for that behavior is that if bookmarks were copyable and you copy some text containing a bookmark from the editor and paste it back that would result in unwanted behavior - there would be two bookmarks with the same name for example.
I hope this information is helpful!
All the best,
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Hi Anders, i have the same problem that you. I need insert text inside bookmarkRangeStart and bookmarkRangeEnd, but preserve bookmark annotation. have you found a solution?
Aren't the suggestions from this thread working for you? Replacing the content between bookmark start and end should be a straight-forward task and it could be implemented using the Selection and Positioning APIs of RadRichTextBox. Here is an example code:
Hope this is helpful.
HI Tanya, it works, but the last character ins not replaced. I'll try replace it, but if you have idea how to do it would be great!
thank you very much
Could you please try removing the invocation of the MoveToPrevious() method for the end position? It seems like I left it by mistake, please excuse me for that.