views:

505

answers:

1

I'm making a simple log viewer which is composed of a big TextBox which shows the file, and a DispatchTimer that updates the TextBox from time to time by setting its Text property.

Whenever the focus is set to the TextBox, it keeps automatically scrolling to the place where the cursor is, even when I'm explicitly issue ScrollToEnd() on it. (In that case, the UI shows the scrollbar "jumping" from the end back to the cursor position).

How can I cause the TextBox to keep its current scrolled position and ignore the position of the cursor?

+1  A: 

For Scrolling it is better to use a ScrollViewer

 <ScrollViewer HorizontalScrollBarVisibility="Auto" Height="80">
   <TextBlock Name="debugLog" />
 </ScrollViewer>

Assuming the Log is not editable.

Sauron
But then, how would I scroll to a specific line? (It is not editable indeed).
Elazar Leibovich
@Sauron, can I scroll to a specific line with `ScrollViewer`? Please edit your answer so that I'll be able to accept it.
Elazar Leibovich