UWP C# 滚动到文本框的底部

4

本文介绍了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

privatevoidTextBox_TextChanged(objectsender,TextChangedEventArgse)
{
    vargrid=(Grid)VisualTreeHelper.GetChild(textBox1,0);
    for(vari=0;i<=VisualTreeHelper.GetChildrenCount(grid)-1;i++)
        {
            objectobj=VisualTreeHelper.GetChild(grid,i);
            if(!(objisScrollViewer))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# 滚动到文本框的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14