开发者

Scroll to bottom on new item. My method freezes scrollbar

开发者 https://www.devze.com 2023-01-13 09:14 出处:网络
I have a ListView that gets updated frequently, at irregular intervals. I want it so that when an update is received the item will be scrolled into view.

I have a ListView that gets updated frequently, at irregular intervals.

I want it so that when an update is received the item will be scrolled into view.

I know the code to do that:

logListView.ScrollIntoView(logListView.Items[logListView.Items.Count - 1]);

I don't know where to put it so that it happens when the ListView is updated.

I've tried putting it in the LayoutUpdated event handler of the ListView, but when I try to scroll during a period when there are no updates (I know there aren't any updates because I've turned the message pump off) the view is stuck at the bottom. I'm guessing this is because scrolling raises a Layo开发者_如何学JAVAutUpdated event.

How do I get the ListView to scroll to the bottom when it receives a new item?


Take a look at the answer to WPF ListBox Scroll when item added. The Items property is an ItemCollection, which implements INotifyCollectionChanged, so you can use the CollectionChanged event. It should work for a ListView as well as a ListBox, but if you're using ScrollIntoView then I suspect you have a ListBox anyway.

INotifyCollectionChanged collection = logListView.Items;
collection.CollectionChanged += collection_CollectionChanged;
0

精彩评论

暂无评论...
验证码 换一张
取 消