Copying content controls using DocumentFragment and then inserting them causes several undesired behaviors.
For example, if the original content control is in "Placeholder mode" (meaning the initial pre-generated text is intact), after the copy operation, its content is treated as user inserted and it is not fully selected on entering the control. Another issue is with Plain Text/Date Picket/Repeating Section control - after the copy, their Properties dialog cannot be shown.
In my usage scenario, I want to allow the users to do some specific actions like changing the font or inserting a table row in those restricted areas.
My current implementation is to modify the source code of RadRichTextBox, expose RespectDocumentProtection and RespectNonDeletableRanges, and temporarily set these properties to false before performing modifications in those restricted areas.
Currently, the properties are available in RadDocumentEditor only.
Importing a document with block-level content controls from XAML causes them to become corrupt. If you scroll to a position in which the said control is only partially visible a NullReferenceException is thrown.
A possible workaround would be to initially save the document as a DOCX (just exporting it to DOCX will not fix the issue as the information is already corrupt).
Another way to reproduce this issue:
1. Create a new document and insert a Rich Text Content Control.
2. Save the document as a XAML file.
3. Reopen the XAML file.
4. Move the caret inside the Content Control.
5. Try to insert a new line by hitting Enter - no new line is added as the content control is marked as Inline Level after the import in step 3.
Case 2:
Create a document with TOC where the content control of the TOC contains some other inlines.
RichTextBox: The RepeatButtonStyle is not merged in the RichTextBox Xaml file when declaring the styles on a window level.
Workaround: Add the dictionaries to the App.xaml file instead of the Window file.
User is not able to select the current date wen Date Picker content control is used.
Select another date and then the current one as a workaround.
If there is an empty cell with a permission range and you go to it by pressing the Tab key from the previous cell and then start typing it removes the annotation range. If the cell with the permission range is not empty and the same technique is used there is an InvalidOperationException thrown with the message: "Selection contains uneditable ranges".
Here is a workaround:
this.radRichTextBox.CommandExecuted += this.RadRichTextBox_CommandExecuted;
private void RadRichTextBox_CommandExecuted(object sender, CommandExecutedEventArgs e)
{
if (e.Command is TabForwardCommand)
{
DocumentPosition caret = this.radRichTextBox.Document.CaretPosition;
if (caret.IsPositionInsideTable)
{
DocumentSelection selection = this.radRichTextBox.Document.Selection;
DocumentPosition start = selection.Ranges.First.StartPosition;
DocumentPosition end = selection.Ranges.Last.EndPosition;
Inline currentInline = start.GetCurrentInline();
if (currentInline is PermissionRangeStart)
{
start.MoveToNext();
}
Inline previousInline = end.GetPreviousInline();
if (previousInline is PermissionRangeEnd)
{
end.MoveToPrevious();
}
this.radRichTextBox.Document.Selection.SetSelectionStart(start);
this.radRichTextBox.Document.Selection.AddSelectionEnd(end);
}
}
}
First, you need to subscribe to the CommandExecuted event. Then change the selection after a TabForwardCommand to exclude the PermissionRangeStart and PermissionRangeEnd elements. Your workaround also works, so there is no need to change it.