开发者

BindingList equivalent in Silverlight? Want to observe changes in collection elements

I was looking around for something like ObservableCollection<T> that would also raise an event whenever the properties of item in the collection change. I came across BindingList<T>, but was disappointed to learn that it's not available in Silverlight.

I'm aware that I could build this fairly easily by subclassing ObservableCollection<T> and subscribing to the Pro开发者_高级运维pertyChanged events of items as they are added (and unsubscribing as they are removed, of course). Before I do that, though, I want to make sure there isn't something I can use out of the box.


The WPF way to do this is to have the objects that you're putting in the ObservableCollection inherit from DependencyObject and have DependencyProperties instead of old fashioned properties and PropertyChanged events. This may mean you have to create a wrapper object that implements this stuff. This will make bindings from UI to the objects in your collection automatically update.

If, on the other hand, you're not doing databinding, and instead you just want a way to get an event to fire in code whenever any property on one of your objects changes, you'd probably need to create your own collection to do this.

http://msdn.microsoft.com/en-us/library/ms752914.aspx has a good explanation of DependencyProperties and examples of the implementation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜