UWP 文本框在收到文本时自动向下滚动 [英] UWP textBox to auto scroll down as text is received

查看:105
本文介绍了UWP 文本框在收到文本时自动向下滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UWP 中有一个简单的文本框,可以在其中自动添加内容.问题是当文本到达文本框底部时,内容仍在添加但变得不可见,除非我使用鼠标向下滚动.

I have a simple textbox in UWP to where content is automatically being added. Issue is when text reach the bottom of the textbox, content is still being added but becomes invisible, unless I use the mice to scroll down.

如何为文本框添加自动向下滚动功能?

How could I add auto scroll down capability to the textbox?

尝试使用 ScrollViewer,但没有运气..

Trying the ScrollViewer, but to no luck..

    <TextBox x:Name="mainTextBox" Grid.Row="2" Grid.Column="0" Margin="5" ScrollViewer.VerticalScrollMode="Auto" TextWrapping="Wrap" Text="" IsReadOnly="True" />

这是更新我的文本框的代码:

Here is the code that updates my textbox:

    private void UpdateStatus(string strMessage, NotifyType type)
    {
        mainTextBox.Text += string.IsNullOrEmpty(mainTextBox.Text) ? strMessage : "\n" + strMessage;

        var peer = Windows.UI.Xaml.Automation.Peers.FrameworkElementAutomationPeer.FromElement(mainTextBox);
        if (peer != null)
        {
            peer.RaiseAutomationEvent(Windows.UI.Xaml.Automation.Peers.AutomationEvents.LiveRegionChanged);
        }
    }

应该怎么做?有人可以帮忙吗?

What should be done? Can someone by a chance help?

推荐答案

这是这篇文章的副本:

UWP C# 滚动到 TextBox 底部

我已经测试过了,效果很好.. :)

I have tested and it works perfectly.. :)

这篇关于UWP 文本框在收到文本时自动向下滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆