I have a WPF application that contains a multiline TextBox that is being used to display debugging text output.
How can I set the TextBox so that as text is appended to the box, it will automatically scroll to the bottom of the textbox?
- I’m using the MVVM pattern.
- Ideally a pure XAML approach would be nice.
- The TextBox itself is not necessarily in focus.
The answer provided by @BojinLi works well.
After reading through the answer linked to by @GazTheDestroyer however, I decided to implement my own version for the TextBox, because it looked cleaner.
To summarize, you can extend the behavior of the TextBox control by using an attached property. (Called ScrollOnTextChanged)
Using it is simple:
Here is the TextBoxBehaviour class: