为 WPF 的 FlowDocumentReader 添加书签
我正在尝试保存和恢复 FlowDocumentReader 中文档的位置以创建书签功能。似乎没有任何内置的可公开访问的查找或搜索功能,给我留下了以下选项:
改用 FlowDocumentPageViewer, 每次打开窗口时保存页面 已调整大小并尽快恢复 当应用程序重新加载时。
循环遍历数组中的所有元素 文档属性 FlowDocumentReader,正在寻找 第一个通过屏幕的 命中测试,然后使用反射 使用内部搜索功能 将该文本重新带回到视图中 稍后。
序列化整个控件。
编写我自己的文档查看器控件。
第一个很烦人,因为我必须放弃 FlowDocumentReader 的两页和滚动查看选项。它还意味着在用户有机会调整窗口大小之前先查找已保存的页面。这是脆弱的,如果用户说在会话之间切换分辨率,则可能会崩溃。
第二个是一个花哨的黑客,可能会起作用,但速度很慢,如果内部发生变化,就会完全崩溃。
第三个看起来是我最好的选择,但它只能让我保存/恢复当前位置,不能设置任意书签。
第四是工作量太大了。这些控件非常太棒了,我只需要这个功能...
还有其他方法可以解决这个问题吗?
I'm trying to save and restore the position of the document within a FlowDocumentReader to create a bookmark feature. There doesn't appear to be any seeking or search feature build in that is publicly accessible, leaving me with the following options:
Use FlowDocumentPageViewer instead,
saving the page each time the window
is resized and restoring it as soon
as the app is reloaded.Loop through all the elements in the
Document property of
FlowDocumentReader, looking for the
first one that passes an on-screen
hit test, then using reflection to
use the internal search features to
bring that text back into view at a
later time.Serialize the entire control.
Write my own document viewer control.
No. 1 is annoying because I'd have to forfeit the two-page and scroll viewing options of FlowDocumentReader. It also means seeking to the saved page before the user has a chance to resize the window. This is fragile and would probably break if the user say, switched resolutions between sessions.
No. 2 is a garish hack that would probably work, but be slow and break completely if the internals ever change.
No. 3 is looking like my best bet, but it only lets me save/restore the current position, not set arbitrary bookmarks.
No. 4 is just too much work. These controls are utterly fantastic, I just need this one feature...
Is there any other way to go about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎适用于页面视图,但不适用于滚动视图,但这没关系。
reader
的类型为FlowDocumentReader
,而 document 是其中的FlowDocument
。设置书签:
恢复书签:
This seems to work well for page views, but not for scroll view, which is okay.
reader
is of typeFlowDocumentReader
, and document is theFlowDocument
within it.Set the bookmark:
Restore the bookmark: