UWP C# Scroll to the bottom of TextBox(UWP C# 滚动到文本框的底部)
问题描述
如何滚动到 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 是您要滚动到底部的文本框.
where textBox1 is the TextBox you want to scroll to the bottom.
这篇关于UWP C# 滚动到文本框的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UWP C# 滚动到文本框的底部
基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
