[英]How can I scroll to the end of a textbox in UWP?
我正在做一个项目,并决定使用 UWP 而不是使用 winforms(我更喜欢)。 我有一个非常简单的TextBox
,我用它来记录发送和接收的数据。 这是一个简单的例子:
这是它的 XAML 代码:
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="18,862,0,0" Text="Logs 🖳" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBox x:Name="LogsTextBox" Margin="18,886,18,0" Text="Welcome to Tiger" TextWrapping="Wrap" VerticalAlignment="Top" Height="88" FontFamily="Courier New" FontSize="12" AcceptsReturn="True" ScrollViewer.VerticalScrollBarVisibility="Visible" IsReadOnly="True"/>
</Grid>
目前,我的TextBox
被我第一次启动项目时获得的默认Grid
包装。
下面看一下LogsTextBox
添加行的方法
/// <summary>
/// A method used to log data to the LogsTextBox
/// </summary>
/// <param name="LogString">The string to be logged</param>
private void Log(string LogString)
{
string TimeString = DateTime.Now.ToString("hh-mm-ss-tt");
LogsTextBox.Text += $"\n[{TimeString}]: {LogString}";
}
从这张图中可以看出,正在记录的数据现在大于TextBox
的高度。 无论如何我可以做到,这样每次调用方法Log
时, LogsTextBox
都会自动滚动到最后?
我在这里找到了几个解决方案,但它们似乎对我不起作用。 即这些:
我能得到的任何帮助将不胜感激
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.