WPF FlowDocument - Absolute Character Position
Posted
by Alan Spark
on Stack Overflow
See other posts from Stack Overflow
or by Alan Spark
Published on 2010-04-02T08:45:22Z
Indexed on
2010/04/02
8:53 UTC
Read the original article
Hit count: 1242
I have a WPF RichTextBox that I am typing some text into and then parsing the whole of the text to do processing on. During this parse, I have the absolute character positions of the start and end of each word.
I would like to use these character positions to apply formatting to certain words. However, I have discovered that the FlowDocument uses TextPointer instances to mark positions in the document.
I have found that I can create a TextRange by constructing it with start and end pointers. Once I have the TextRange I can easily apply formatting to the text within it. I have been using GetPositionAtOffset to get a TextPointer for my character offset but suspect that its offset is different from mine because the selected text is in a slightly different position from what I expect.
My question is, how can I accurately convert an absolute character position to a TextPointer?
© Stack Overflow or respective owner