简体   繁体   English

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

[英]wpf DocumentViewer - get ITextPointer by GlyphRun and vice versa

Just wondering whether anybody has tried to hack into WPF DocumentViewer in order to make it more useful. 只是想知道是否有人尝试入侵WPF DocumentViewer以便使其更有用。 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. 我已经花了将近一个星期的时间,试图根据我使用反射提取的方法为该控件创建更强大的API。

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 . 选定的文本具有EndStart属性,这些属性返回ITextPointers Also I have a collection of GlyphRuns extracted using this code . 我还有使用此代码提取的GlyphRuns的集合。 And now finally I want to find out which GlyphRun contains selection start. 现在,我终于想找出哪个GlyphRun包含选择开始。

So I want to know how to convert ITextPointers into GlyphRuns and vice versa. 所以我想知道如何将ITextPointers转换为GlyphRuns ,反之亦然。 I understand that they do not have 1:1 relationship. 我了解他们没有1:1的关系。 This control with closed API and last week spent in Reflector doesn't let me sleep well. 这个具有封闭API的控件以及上周花在Reflector上的控件无法让我睡个好觉。 I hope maybe somebody tried to do it before or seen code samples and will be able to guide me through these jungles. 我希望也许有人尝试过之前做过,或者看到过代码示例,并且能够引导我通过这些丛林。

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 坦率地说,最好是找到适合您需求的第三方控件,例如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. 或者,如果这不是一种选择,则您可能可以花费大量的时间来创建自己的控件,以使它起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM