0

我在 Avalon UI 上有一个聊天应用程序。消息显示在 ScrollViewer 中。接收或发送消息时,我需要将消息列表滚动到新消息。

4

1 回答 1

0

你可以使用ScrollViewer.ScrollToEnd() 方法

这是我的一个应用程序的使用示例:

public class ClientPage : UserControl
{
    private ScrollViewer messageLogScrollViewer;

    public ClientPage()
    {
        this.InitializeComponent();
        messageLogScrollViewer = this.FindControl<ScrollViewer>("MessageLogScrollViewer");
    }

    private void InitializeComponent()
    {
        AvaloniaXamlLoader.Load(this);
    }

    public void ScrollTextToEnd()
    {
        messageLogScrollViewer.ScrollToEnd();
    }
}

根据您的特定用例,您可能需要使用该ScrollViewer.LineDown() 方法或任何其他提供的方法。

此外,您还可以自己设置偏移量。

于 2020-11-30T07:25:13.603 回答