如何通过WPF中的代码转到flowdocument阅读器中的特定页码?

发布于 2024-08-09 02:18:25 字数 81 浏览 8 评论 0原文

流程文档阅读器中有一个 pagenumber 属性。但该属性是只读的。有什么方法可以转到流程文档阅读器中的特定页码。请帮忙。

谢谢。

There is a pagenumber property in flowdocument reader.But that property is readonly. Is there any way to goto particular page number in flowdocument reader.Please help.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝不放开 2024-08-16 02:18:25

如果您愿意限制用户分页显示,请改用 FlowDocumentPageViewer:它有一个 GoToPage() 方法。由于某种原因,FlowDocumentReader 似乎没有提供 GoToPage();我猜这是因为 FlowDocumentReader 并不总是处于有意义的分页模式(用户可以选择连续滚动视图),并且在有意义时为此提供自己的 UI。

您可以尝试向其发送 NavigationCommands.GoToPage 命令,但这仅记录为适用于 FlowDocumentPageViewer 和 DocumentViewer;我还没有在 FlowDocumentReader 上测试过它。

If you are willing to restrict your users to paged display, use FlowDocumentPageViewer instead: this has a GoToPage() method. For some reason GoToPage() doesn't seem to be offered on FlowDocumentReader; I'd guess this is because FlowDocumentReader isn't always in a mode where paging is meaningful (the user can select a continuous scrolling view), and provides its own UI for this when it is meaningful.

You could try sending it the NavigationCommands.GoToPage command, but this is only documented as working on FlowDocumentPageViewer and DocumentViewer; I haven't tested it on FlowDocumentReader.

柒夜笙歌凉 2024-08-16 02:18:25

如果您跟踪 FlowDocumentReader 中包含的 FlowDocument 上的块,
比您可以简单地使用:

// Getting a block by index
YourReader.Document.Blocks.ElementAt(index).BringIntoView();

// Showing Last Block
YourReader.Document.Blocks.LastBlock.BringIntoView();

// Showing the last Inline
(YourReader.Document.Blocks.LastBlock as Paragraph).Inlines.LastInline.BringIntoView();

适用于 FlowDocumentReader 的 ViewingModes 页面。

如果您想在滚动模式下执行此操作,则必须沿着视觉树向下搜索 ScrollViewer,
像这样的东西:

        public static ScrollViewer FindScroll(Visual visual)
        {
            if (visual is ScrollViewer)
                return visual as ScrollViewer;

            ScrollViewer searchChiled = null;
            DependencyObject chiled;

            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(visual); i++)
            {
                chiled = VisualTreeHelper.GetChild(visual, i);
                if (chiled is Visual)
                    searchChiled = FindScroll(chiled as Visual);
                if (searchChiled != null)
                    return searchChiled;
            }

            return null;
        }

ScrollViewer scroller = FindScroll(YourReader as Visual);
if (scroller != null) 
   (scroller as ScrollViewer).ScrollToBottom();

If you keep track of the Blocks on the FlowDocument contained in the FlowDocumentReader,
than you can simply use:

// Getting a block by index
YourReader.Document.Blocks.ElementAt(index).BringIntoView();

// Showing Last Block
YourReader.Document.Blocks.LastBlock.BringIntoView();

// Showing the last Inline
(YourReader.Document.Blocks.LastBlock as Paragraph).Inlines.LastInline.BringIntoView();

This works only on the page ViewingModes of the FlowDocumentReader.

if you whould like to do so on the scroll mode, you must go down the visual tree and search for the ScrollViewer,
somthing like this:

        public static ScrollViewer FindScroll(Visual visual)
        {
            if (visual is ScrollViewer)
                return visual as ScrollViewer;

            ScrollViewer searchChiled = null;
            DependencyObject chiled;

            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(visual); i++)
            {
                chiled = VisualTreeHelper.GetChild(visual, i);
                if (chiled is Visual)
                    searchChiled = FindScroll(chiled as Visual);
                if (searchChiled != null)
                    return searchChiled;
            }

            return null;
        }

ScrollViewer scroller = FindScroll(YourReader as Visual);
if (scroller != null) 
   (scroller as ScrollViewer).ScrollToBottom();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文