WPF:更改 ListView 观察到的集合中的项目
我有一个绑定到项目集合的 ListView
(带有 GridView
)。这是非常标准的东西。该集合是一个ObservableCollection
。
现在假设我更改了集合中某个项目的某些属性。我如何告诉ListView
这一点?该列表有数万行长,因此我需要能够告诉它不要重新加载整个集合,只是更新了一些单个元素。
有什么想法吗?
I have a ListView
(with a GridView
) bound to a collection of items. This is pretty standard stuff. The collection is an ObservableCollection
.
Now let's say I change some property of an item in the collection. How do I tell the ListView
about this? The list is tens of thousands of lines long, so I need to be able to tell it not to reload the entire collection, just that I updated some single element.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的对象实现某种属性更改通知(最常见的方法是实现接口
INotifyPropertyChanged
) - 那么列表将知道自动更新属性更改。If your objects implement some kind of property change notification (the most common way is to implement the interface
INotifyPropertyChanged
) - then the list will know to update the property change automatically.问题是,正如您从单步执行代码中看到的那样,没有人在监听您的各个项目的
PropertyChanges
。您需要将集合的每一行(项目)绑定到
PropertyChanged
事件,最简单的方法是重写ObservableCollection
。The problem is, as you can see from stepping through the code, is no one is listening to for
PropertyChanges
on your individual items.You need to bind each row (item) of your collection to the
PropertyChanged
event and the easiest way to do this is by overridingObservableCollection
.