I am using RichEditBox for a rich text editor: I use different colors for different keywords in the text while user types the text in the richEditBox control.
Before making changes I save current selection position:
ITextSelection selection = richEditBox.Document.Selection;
int originalStartPosition = selection.StartPosition;
int originalEndPosition = selection.EndPosition;
then I change color of some parts of the text, for example:
selection.SetRange(startIndex, stopIndex);
selection.CharacterFormat.ForegroundColor = Colors.Red;
and after making all changes I restore current selection position:
selection.SetRange(originalStartPosition, originalEndPosition);
This works fine, but SetRange() function affects scrolling position of the text in richEditBox, because it automatically scrolls to make the selected part of the text visible on the screen. So, after all color modifications the scroll position of richEditBox control becomes modified.
Final SetRange() function call puts cursor in its initial place, but not the scroll position.
So, my question is: how can I restore scrolling position of richEditBox control after making color changes? Or how can I modify text color without affecting the scroll position?