How to set the scroll position of a WPF RichTextBox to view a specific word or line

Viewed 76

I want to write a TTS program that automatically scrolls to the spoken word. I found a solution for paragraphs. I am not using paragraphs, but I adapt this solution to use the characterIndex of the current word:

        TextPointer startTextRange = richtTextselectionView.Document.ContentStart.GetPositionAtOffset(characterIndex);
        verticalOffset = startTextRange.GetCharacterRect(LogicalDirection.Forward).Y;
        richtTextselectionView.ScrollToVerticalOffset(verticalOffset);

This is the Result:

GIF of the current Program code. The scroll speed is too slow, and the viewport only reaches until eight instead of twelve

The Problem is that the text box is scrolling too slow.

I already tried to multiply the verticalOffset with a constant but the behavior seems to be nonlinear...

I am using .Net6.0 and MaterialDesignThemes in the latest version.

0 Answers
Related