Using ObservableCollection in ASP.NET
I need to use functionality that ObservableCollection
provides, in my asp.net app. My only concern is that this class is a part of WindowsBase assembly and I'm not sure if it's a good idea to include a windows assembly in a web 开发者_开发百科project.
Any ideas/comments?
Thanks!
If you have a creative use for ObservableCollection
outside of WPF, I don't see any reason you should not take advantage of it. Even Microsoft says:
Before implementing your own collection, consider using
ObservableCollection<T>
or one of the existing collection classes, such asList<T>
,Collection<T>
, andBindingList<T>
, among many others.
This article has an example of an ObservableCollection
in WPF. However, the author makes this statement at the end of the article:
Although this application made use of the binding support provided by the ObservableCollection class and also reacted to its CollectionChanged event in order to update the user interface, you needn't use the class this way. Because it notifies listeners that its contents have changed, you can replace any List or Collection instance that you use with an ObservableCollection instance (even if you're not creating a WPF application) and then hook up event handlers to notify clients that the collection's contents have changed.
精彩评论