I need help in scrolling to highlighted text/string positions in a rich text box. I was able to find text and highlight it but I want the user to be able to click on a Next button and that event to scroll to the vertical offset position of the first occurrence of the highlighted word to the next and so on after each click. Any help specifically with finding the position for the vertical offset of the line of the highlighted text would be helpful as well. Thanks in advance.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
I found an answer to a similar question here. Below is the code that I believe will do the trick for you.
I had two
TextPointer
s with which I created aTextRange
, then used.ApplyPropertyValue
on that to set background colour. Then I tried......but it was unreliable. What I eventually discovered worked - ostensibly reliably - was using the
.Start
of theTextRange
I created from the samefromTextPointer
:I would guess that certain actions - possibly the creation of a
TextRange
but more likely invocation of.ApplyPropertyValue
- trigger enough position normalisation within the widget and/or textRange object that the.BringIntoView()
is then reliable.Perhaps this isn't necessary for the
Selection
- as inWard
s answer - but I wasn't manipulating theSelection
and this question doesn't mention theSelection
specifically either, so posting here in-case it helps some other poor soul avoid hours of WPF "fun".