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.
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.
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.
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.
foreach (Span span in paragraphCopy.EnumerateChildrenOfType<Span>())
{
if (string.IsNullOrEmpty(span.Text))
{
span.Text = " ";
}
}