2

我正在开发一个具有绑定到 FlowDocumentScrollViewer 的 FlowDocument 的 wpf 应用程序。滚动 FlowDocumentScrollViewer 时,我收到 InvalidOperationException: 'This TextNavigator' has no scoping text element。这会导致应用程序崩溃。

异常详情:

System.InvalidOperationException: 'This TextNavigator' has no scoping text element.
at System.Windows.Documents.TextPointer.MoveToElementEdge(ElementEdge edge)
at System.Windows.Documents.TextPointer.System.Windows.Documents.ITextPointer.MoveToElementEdge(ElementEdge edge)
at System.Windows.Documents.TextPointerBase.GetFollowingNonMergeableInlineContentStart(ITextPointer position)
at System.Windows.Documents.TextSelection.get_PropertyPosition()
at System.Windows.Documents.TextSelection.GetCurrentValue(DependencyProperty formattingProperty)
at System.Windows.Documents.TextSelection.GetCaretBrush(TextEditor textEditor)
at System.Windows.Documents.TextSelection.UpdateCaretStateWorker(Object o)
at System.Windows.Documents.TextSelection.UpdateCaretState(CaretScrollMethod caretScrollMethod)
at System.Windows.Documents.TextSelection.System.Windows.Documents.ITextRange.NotifyChanged(Boolean disableScroll, Boolean skipEvents)
at System.Windows.Documents.TextRangeBase.EndChange(ITextRange thisRange, Boolean disableScroll, Boolean skipEvents)
at System.Windows.Documents.TextRange.System.Windows.Documents.ITextRange.EndChange(Boolean disableScroll, Boolean skipEvents)
at System.Windows.Documents.TextRange.ChangeBlock.System.IDisposable.Dispose()
at System.Windows.Documents.TextEditorMouse.OnMouseMoveWithFocus(TextEditor This, MouseEventArgs e)
at System.Windows.Documents.TextEditorMouse.OnMouseMove(Object sender, MouseEventArgs e)
at System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 

生成 FlowDocument 时没有任何异常。我一直在网上搜索,但没有找到可以提供帮助的信息。

4

1 回答 1

0

我没有直接的解释,但我今天遇到了同样的异常。在我的情况下,答案是:不要选择一个空的BlockUIContainerFlowDocument以及你在那里拥有的任何“更适合”的组件。

这是我的 xaml,它是一个用户控件,我创建了一个实例并将其放在我的窗口中(它应该就像我在“瑞士刀”应用程序中决定做什么的第TabItem一个内部的“主页” TabControl)。注意BlockUIContainer(用于托管类似笔记的 UI,粘贴任何文本并将其保存到转储文件),我注释掉了它的内容:

    <DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        
        <FlowDocumentScrollViewer 
            IsToolBarVisible="False" Zoom="60" 
            HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <FlowDocument>
                <Paragraph><Run FontSize="24">Quick start :</Run></Paragraph>
                <List MarkerOffset="16" LineHeight="16">
                    <ListItem><Paragraph>Open application directory in <Hyperlink NavigateUri="" RequestNavigate="ExploreAppDir_RequestNavigate">Explorer</Hyperlink>...</Paragraph></ListItem>
                    <ListItem><Paragraph>Manage <Hyperlink NavigateUri="" RequestNavigate="GalleryManager_RequestNavigate">images gallery</Hyperlink>...</Paragraph></ListItem>
                    <ListItem><Paragraph>Create a model...</Paragraph></ListItem>
                    <ListItem><Paragraph>Launch server...</Paragraph></ListItem>
                </List>
                
                <BlockUIContainer>
                    <!--DockPanel Height="100">
                        <TextBox DockPanel.Dock="Top" />
                        <Grid />
                    </DockPanel-->
                </BlockUIContainer>
                
                <Paragraph>
                    <Bold>What to do next ?</Bold>
                </Paragraph>
            </FlowDocument>
        </FlowDocumentScrollViewer>
        
    </DockPanel>

我注释掉了 的内容BlockUIContainer,当我开始从文本“下一步做什么”中选择BlockUIContainer组件时,我得到了异常

当我取消注释BlockUIContainer内容时,即,现在我有了那个文本框和一个占位符网格,我可以选择任何东西(任何FlowDocument项目),浏览BlockUIContainer组件(包括它的文本框),等等,无一例外

我根本不明白这个例外。BlockUIContainer根据调用堆栈中的文字,当没有子内容时,似乎是一个空的无法转发内容选择范围,我觉得这有点疏忽。OP 的问题发生在他滚动时,但并不表明他有任何选择,所以可能是另一个文本边界问题。

于 2021-11-12T15:17:37.417 回答