4

When I insert a UIElement into RichTextBox (such as a Button in BlockUIContainer)。I always got an InvalidOperationException said "This TextNavigator No Scoping Text Element" when I edit the richtextbox(especially select elements including UIElements).

The exception details:

System.Windows.Documents.TextPointer.MoveToElementEdge(ElementEdge edge) System.Windows.Documents.TextPointer.System.Windows.Documents.ITextPointer.MoveToElementEdge(ElementEdge edge) System.Windows.Documents.TextPointerBase.GetFollowingNonMergeableInlineContentStart(ITextPointer position) System.Windows.Documents.TextSelection.get_PropertyPosition() System.Windows.Documents.TextSelection.GetCurrentValue(DependencyProperty formattingProperty)

“This TextNavigator” No Scoping Text Element。

I have dived into it and found the exception was thrown here:

internal void MoveToElementEdge(ElementEdge edge)
{
  ValidationHelper.VerifyElementEdge(edge, "edge");
  this.VerifyNotFrozen();
  this._tree.EmptyDeadPositionList();
  this.SyncToTreeGeneration();
  TextTreeTextElementNode scopingNode = this.GetScopingNode() as TextTreeTextElementNode;
  if (scopingNode == null)
  {
    throw new InvalidOperationException(SR.Get("NoScopingElement", new object[] { "This TextNavigator" }));
  }
  this.MoveToNode(this._tree, scopingNode, edge);
}

It seems the problem is related to TextTreeTextElementNode. But I cannot trace anymore since it's too complex for me. I guess The UIElement cannot wrapped by this "TextTreeTextElementNode" and this cause a null is returned.

I have tried to search google, but found no valuable information only a feedback to Microsoft.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Simon. Li
  • 404
  • 2
  • 11

0 Answers0