C# 将UIElement插入RichTextBox时崩溃

C# 将UIElement插入RichTextBox时崩溃,c#,wpf,richtextbox,uielement,C#,Wpf,Richtextbox,Uielement,当我将UIElement插入RichTextBox(例如BlockUIContainer中的按钮)时,当我编辑RichTextBox(尤其是选择包含UIElements的元素)时,我总是得到一个InvalidOperationException表示“此TextNavigator无作用域文本元素” 例外情况详情: System.Windows.Documents.TextPointer.MoveToElementEdge(ElementEdge) System.Windows.Documents.

当我将
UIElement
插入
RichTextBox
(例如
BlockUIContainer
中的
按钮
)时,当我编辑RichTextBox(尤其是选择包含UIElements的元素)时,我总是得到一个
InvalidOperationException
表示“此TextNavigator无作用域文本元素”

例外情况详情:

System.Windows.Documents.TextPointer.MoveToElementEdge(ElementEdge) System.Windows.Documents.TextPointer.System.Windows.Documents.ITextPointer.MoveToElementEdge(ElementEdge) System.Windows.Documents.TextPointerBase.GetFollowerNonMergeableInLineContentStart(ITextPointer位置) System.Windows.Documents.TextSelection.get_PropertyPosition() System.Windows.Documents.TextSelection.GetCurrentValue(DependencyProperty formattingProperty)

“This TextNavigator”无范围文本元素

我深入研究了一下,发现异常是在这里抛出的:

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);
}
问题似乎与TextTreeTextermentNode有关。但是我不能再追踪了,因为它对我来说太复杂了。我猜UIElement不能被这个“TextTreeTextermentNode”包装,这会导致返回null


我曾尝试搜索谷歌,但没有找到有价值的信息,只找到了对微软的反馈。

你解决了这个问题吗?我也有同样的问题。谢谢