如何让WPF文本框自动向下滚动

How to make WPF Textbox automaticly scroll down

我的申请中有一个 TextBox 用于显示进度。我希望我的 TextBox 自动滚动到 TextBox 的底部。

这是我试过的:

TextBox.ScrollToEnd();

//and 

TextBox.SelectionStart = TextBox.Text.Length;
TextBox.ScrollToCaret();

//and 

TextBoxBase.ScrollToEnd().

我的xaml代码:

<TextBox  x:Name="TextBox" Grid.ColumnSpan="2" Height="77" Margin="0,106,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto" IsReadOnly="True" Cursor="Arrow" />

我是 WPF 的新手,解释代码片段会帮助我理解。

如果将 AcceptsReturn 属性 设置为 true:

TextBox.ScrollToEnd() 应该可以工作

<TextBox x:Name="TextBox" ... AcceptsReturn="True" />