为什么好(在WPF,C#,实体框架)来绑定列表框
到的ObservableCollection
时创建在对象集
(从实体框架),而不是绑定到对象集
直接?
Why is it better (in WPF, C#, Entity Framework) to bind ListBox
to an ObservableCollection
created upon the ObjectSet
(from Entity Framework) rather than binding to ObjectSet
directly?
还有一个问题:
当我绑定列表框
到的ObservableCollection
,任何增加的收集更新列表框
。大。但的ObservableCollection
是在的ObjectContext
创建(实体框架),并加入新的项目,以收集不加项目的背景下...如何解决这个????
One more question:
When I bind ListBox
to ObservableCollection
, any additions to the collection updates ListBox
. Great. But ObservableCollection
was created upon ObjectContext
(in Entity Framework) and adding a new item to the collection doesn't add the item to the context... how to solve this????
推荐答案
的ObservableCollection工具 INotifyPropertyChanged的
以及 INotifyCollectionChanged
其中,既WPF使用重新绑定元素到用户界面。因此,你可以添加一个项目到的ObservableCollection,马上用户界面将与你没有code交互更新。 对象集
实现两者都不是,所以犯规得到这个功能。
ObservableCollection implements INotifyPropertyChanged
as well as INotifyCollectionChanged
, both of which WPF uses to rebind elements to the UI. Thus, you could add an item to the ObservableCollection and immediately the UI would update with no code interaction from you. ObjectSet
implements neither, and so doesnt get this functionality.
相关推荐
最新文章