首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >滚动时FlowDocumentScrollViewer崩溃

滚动时FlowDocumentScrollViewer崩溃
EN

Stack Overflow用户
提问于 2018-06-06 06:58:33
回答 1查看 73关注 0票数 2

我正在开发一个wpf应用程序,它有一个绑定到一个FlowDocument的FlowDocumentScrollViewer。当滚动FlowDocumentScrollViewer时,我得到了一个InvalidOperationException:'This TextNavigator‘没有限定作用域的文本元素。这会导致应用程序崩溃。

异常详细信息:

代码语言:javascript
复制
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时,我不会得到任何异常。我一直在网上搜索,但没有发现任何有用的信息。

EN

回答 1

Stack Overflow用户

发布于 2021-11-12 15:17:37

我没有直接的解释,但我今天遇到了同样的例外。在我的例子中,答案是:不要选择一个空的以及任何“更适合”的FlowDocument组件。

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

代码语言:javascript
复制
    <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)。(它的文本框),以及它之外的(无一例外地是)。

我一点也不明白这个例外。根据调用堆栈中的单词,当没有子内容时,空的BlockUIContainer似乎不能转发内容选择边界,我发现这有点疏忽。OP的问题发生在他滚动时,但并不表示他有任何选择,因此很可能是另一个文本边界问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50714048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档