Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 629
Snowbear Avatar asked Mar 02 '11 20:03

Snowbear


1 Answers

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.

like image 185
justin.m.chase Avatar answered Oct 03 '22 00:10

justin.m.chase