WPF ListView绑定问题 [英] WPF ListView Binding Problem
问题描述
我已将控件的 ItemsSource
属性绑定到 ObservableCollection
项目(从 INotifyPropertyChanged
),但是当我向集合中添加项目时, ListView
不会在表单中更新。
如果我在添加新项目的行之后的代码中放置断点,则 ListView.ItemsSource
已正确设置并且指示的集合有项目,但 ListView.Items.Count
是0.
任何帮助将不胜感激。
编辑===============
没有绑定错误显示在编译器的输出窗口中。
I've bound the control's ItemsSource
property to an ObservableCollection
of items (deriving from INotifyPropertyChanged
), but when I add items to the collection, the ListView
doesn't update in the form.
If I put a breakpoint in the code after the line that adds the new items, the ListView.ItemsSource
is set correctly and the indicated collection has items, but ListView.Items.Count
is 0.
Any help would be appreciated.
EDIT ===============
There are no binding errors displayed in the compiler's output window.
推荐答案
没关系 - 问题是我在检索数据之前正在设置ViewModel的新实例。
Nevermind - the problem was that I was instatiating a new instance of the ViewModel before retrieving the data.
这篇关于WPF ListView绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!