wpf DocumentViewer - 通过 GlyphRun 获取 ITextPointer,反之亦然

发布于 2024-10-20 00:36:30 字数 796 浏览 6 评论 0原文

只是想知道是否有人尝试侵入 WPF DocumentViewer 以使其更有用。我已经花了近一周的时间尝试根据我使用反射提取的方法为该控件创建更强大的 API。

每个人都知道如何通过反射从文档查看器获取选定的文本,但我的任务更复杂。 所选文本具有返回 ITextPointersEndStart 属性。我还收集了使用提取的 GlyphRuns 此代码。现在最后我想找出哪个 GlyphRun 包含选择开始。

所以我想知道如何将 ITextPointers 转换为 GlyphRuns ,反之亦然。我知道他们没有1:1的关系。这个具有封闭 API 的控件以及上周在 Reflector 中度过的时间让我睡不好觉。我希望也许有人尝试过这样做或看过代码示例,并且能够引导我穿越这些丛林。

Just wondering whether anybody has tried to hack into WPF DocumentViewer in order to make it more useful. I've spent almost a week already trying to create more powerful API for this control based on it's methods which I extract using reflection.

Everybody knows how to get selected text from document viewer via reflection but my task is more complicated. Selected text has End and Start properties which return ITextPointers. Also I have a collection of GlyphRuns extracted using this code. And now finally I want to find out which GlyphRun contains selection start.

So I want to know how to convert ITextPointers into GlyphRuns and vice versa. I understand that they do not have 1:1 relationship. This control with closed API and last week spent in Reflector doesn't let me sleep well. I hope maybe somebody tried to do it before or seen code samples and will be able to guide me through these jungles.

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

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

发布评论

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

评论(1

最偏执的依靠 2024-10-27 00:36:30

我建议您放弃这种方法。像这样进行大量的私人反射不应该作为生产代码的基础,它非常脆弱并且在某些情况下是完全禁止的。坦率地说,您最好找到适合您需求的第三方控件,例如 www.infragistics.com

或者如果这不是一个选择,您可能可以在需要花时间让它工作的情况下创建自己的控件。

I would recommend that you abandon this approach. Doing lots of private reflection like this is not something you should be basing production code on, its very brittle and downright forbidden in some contexts. Frankly, you're better off finding a 3rd party control that suits your needs such as www.infragistics.com

Or if that's not an option you can probably create your own control in the amount of time you'll have to sink into getting this to work.

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