UWP C#滚动到TextBox的底部 [英] UWP C# Scroll to the bottom of TextBox
本文介绍了UWP C#滚动到TextBox的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何滚动到UWP应用的文本框底部?
How do you scroll to the bottom of a TextBox for a UWP app?
在我过渡到UWP时,这一直不是直截了当的问题之一.
With my transition to UWP, this has been one of the questions that hasn't been straight-forward.
我曾经能够使用它:
textBox.SelectionStart = textBox.TextLength;
textBox.ScrollToCaret();
但是,这不适用于UWP应用
But, this doesn't work for UWP apps
推荐答案
如果有人需要滚动到UWP应用程序中TextBox的底部,则:
If anyone needs to scroll to the bottom of a TextBox in UWP apps:
https://code.msdn.microsoft.com/windowsapps/How-to-scroll-to-the-a8ea5867
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var grid = (Grid)VisualTreeHelper.GetChild(textBox1, 0);
for (var i = 0; i <= VisualTreeHelper.GetChildrenCount(grid) - 1; i++)
{
object obj = VisualTreeHelper.GetChild(grid, i);
if (!(obj is ScrollViewer)) continue;
((ScrollViewer)obj).ChangeView(0.0f, ((ScrollViewer)obj).ExtentHeight, 1.0f);
break;
}
}
}
其中textBox1是要滚动到底部的TextBox.
where textBox1 is the TextBox you want to scroll to the bottom.
这篇关于UWP C#滚动到TextBox的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文