比对象集的ObservableCollection更好 [英] ObservableCollection better than ObjectSet

查看:132
本文介绍了比对象集的ObservableCollection更好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么好(在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.

这篇关于比对象集的ObservableCollection更好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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