获取 FlowDocumentPageViewer 的当前页面
我有一个 FlowDocumentPageViewer 控件,我从后面的代码中填充该控件。我正在添加 3-4 个项目的文本。我需要知道第 1,2,3... 项在哪一页结束。
这些项目被循环添加到 FlowDocument 中,然后最后我有
flowDocumentPageViewer.Document = resultsDocument;
但是,即使这样,即使我调用,
flowDocumentPageViewer.PageCount
我仍然得到 0。如果我执行一些事件(例如单击)并在窗口渲染后打印上面的 PageCount,它会打印正确的值。但是,在填充 FlowDocument 时,我需要该值的运行总计。我希望有人知道某种文本指标的技巧或任何其他可以解决这个问题的方法。
I have a FlowDocumentPageViewer control that I am populating from the code behind. I am adding text from 3-4 items. I need to know on what page item 1,2,3... ends.
These items get added to a FlowDocument in a loop and then at the end I have
flowDocumentPageViewer.Document = resultsDocument;
However, even then if I call
flowDocumentPageViewer.PageCount
I still get 0. If I do some event like a click and print the above PageCount after the window renders, it does print the correct value. However, I need a running total of this value as I populate the FlowDocument. I am hoping someone knows some kind of trick with text metrics or any other way that this could be solved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您别无选择,只能触发控件的(虚拟)渲染来获取此类信息。
最简单的方法是在 FlowDocumentPageViewer 上强制执行 updateLayout() ,但这意味着它会在您获取信息之前显示结果,这可能不是您想要的。
如果您不希望显示内容,也可以使用
Arrange()
方法:http://msdn.microsoft.com/en-us/library/system.windows.uielement.arrange.aspx
在您的控件上使用此后你应该得到更新的信息。
You have no choice but to trigger a (virtual) render of your control to get this kind of info.
the easiest way is to force a
updateLayout()
on the FlowDocumentPageViewer, but this means it'll show the result before you get the info which is probably not what you want.you can also use the
Arrange()
method if you don't want the content to be shown:http://msdn.microsoft.com/en-us/library/system.windows.uielement.arrange.aspx
after using this on your control you should get the updated info.
我也遇到了同样的问题,说实话我现在仍然如此。任何 updateLayout() 都没有帮助。现在,在将文档分配给查看器后,我使用计时器在一秒钟后获取页数。工作正常。
I had the same problem and to be honest I still do. Any updateLayout() did not help. Now I use a timer to get the pagecount a second later after I assigend to document to the viewer. Works fine.