A Comment holds annotation markers, which specify for which range of document elements it refers. Every Comment has a corresponding CommentRangeStart and CommentRangeEnd, which are inline elements. These two elements specify the comment's location as follows.
- CommentRangeStart: Specifies the start of a comment annotation.
- CommentRangeEnd: Specifies the end of a comment annotation.
Example 1 shows how to create a Comment and add its CommentRangeStart and CommentRangeEnd elements in a paragraph.
[C#] Example 1: Add a comment to a paragraph
Comment comment = document.Comments.AddComment(); paragraph.Inlines.Add(comment.CommentRangeStart); paragraph.Inlines.AddRun("text"); paragraph.Inlines.Add(comment.CommentRangeEnd);
The AddComment() method of the Comments collection of a document creates a new comment and return it. The location of the comment is around a run with text "text". Note, that the paragraph should belong to the same document as the one passed to the constructor of the Comment or an exception is going to be thrown.
Example 2 shows how you can insert a previously created Comment object in a document by using RadFlowDocumentEditor. The InsertComment() method will insert the comment's start and end elements.
[C#] Example 2: Insert previously created comment
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(new RadFlowDocument()); editor.InsertComment(comment);
Example 3 demonstrates how you can use another overload of RadFlowDocumentEditor's InsertComment() method. In this case, a string representing the text of the Comment and two inline elements are passed. The two inline elements specify the element prior, which the CommentRangeStart should be added and the element after which the CommentRangeEnd should be added.
[C#] Example 3: Insert comment around run
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(new RadFlowDocument()); Run run = editor.InsertText("text"); editor.InsertComment("My sample comment.", run, run);
The Comment class exposes several properties which allow you to customize information about it:
- Author: Property of type string specifying the author of the comment.
- Initials: Property of type string specifying the author' initials.
- Date: DateTime property showing the moment the comment was created.
Example 4 shows how you can add a Table to a Comment.
[C#] Example 4: Add blocks to a comment
Paragraph paragraph = comment.Blocks.AddParagraph(); Table table = comment.Blocks.AddTable();