WPF ListBox 自动滚动到结束 [英] WPF ListBox Scroll to end automatically

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

问题描述

在我的应用程序中,我有一个带有项目的 ListBox.该应用程序是用 WPF 编写的.

In my application, I have a ListBox with items. The application is written in WPF.

如何自动滚动到最后添加的项目?我希望在添加新项目后将 ScrollViewer 移动到列表的末尾.

How can I scroll automatically to the last added item? I want the ScrollViewer to be moved to the end of the list when new item has been added.

有没有像 ItemsChanged 这样的事件?(我不想使用 SelectionChanged 事件)

Is there any event like ItemsChanged? (I don't want to use the SelectionChanged event)

推荐答案

试试这个:

lstBox.SelectedIndex = lstBox.Items.Count -1;
lstBox.ScrollIntoView(lstBox.SelectedItem) ;

在您的主窗口中,这将选择并关注列表中的最后一项!

In your MainWindow, this will select and focus on last item on the list!

这篇关于WPF ListBox 自动滚动到结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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