Is there a way to scroll, for example, to the start of a RichTextBox from C# code?
I’m filling its content programmatically (with paragraphs containing images and run texts) and when the filling completes the location of the scroll is at the bottom of RichTextBox. I would like to set it to top, instead of bottom.
I have tried to created a workaround with wrapping my RichTextbox with a ScrollViewer: However when I call its ScrollToVerticalOffset on the ScrollViewer nothing happens, the UI doesn’t get updated.
You need to reach inside the RichTextBox control to get hold of its internal
ScrollViewerthen callScrollToVerticalOffset. This is done with the help ofVisualTreeHelper, see this blog for the small source code of a couple of useful extension methods. With theVisualTreeEnumerationclass available you can use the following code to get theScrollViewer