简体   繁体   中英

UWP textBox to auto scroll down as text is received

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?

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?

This is a duplicate of this post:

UWP C# Scroll to the bottom of TextBox

I have tested and it works perfectly.. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM