wpf DocumentViewer - get ITextPointer by GlyphRun and vice versa
Asked Answered
H

1

35

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.

Horse answered 2/3, 2011 at 20:2 Comment(4)
As you said, there is no 1:1 relationship. Furthermore, GlyphRun only inherits from object. However, it does contain noteworthy methods. (I have not tried any of them.) For instance, GlyphRun.ComputeAlignmentBox() returns a Rect, which may contain locational data. I think that's the key... relating the GlyphRun and TextPointer locational data.Immodest
can you share some code with us so we can make a some tries alsoFructose
@HBMAAM, During the year I found more or less working solution, I'm going to post it here, but it'll take some time.Horse
@Horse liaaarSunup
R
1

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.

Robeson answered 12/5, 2012 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.