简体   繁体   中英

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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