-
Hi Guys, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
The problem is that GetPositionAtOffset takes offset in symbols while you are providing offset in characters. You are assuming that the string will stay uninterrupted, but that is not the case. For example, when you make the word "commodo" bold (by selecting it and pressing Ctrl+B) and then pressing your button, it will miss even more letters - there are more symbols in the text to mark the formatted spans. What are you actually trying to do? Highlight a line? Would it be different line with line-wrapping on and off? Or highlighting a specific text? If specific text, what if it is split across paragraph or other formatting? You might need to go through the runs one by one to find the one that your character offset falls in. |
Beta Was this translation helpful? Give feedback.
https://learn.microsoft.com/en-us/dotnet/api/system.windows.documents.textpointer would be a useful reading to you. It has a simple example of how to find a string inside a text. You can call it in your demo like this:
But as I said, depending on where the text comes from and what users can do in the text box, this will break easily.