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

查看:732
本文介绍了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) ;

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

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

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

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