ManfredP
ManfredP

Reputation: 1057

C# Binding to an ObservableCollection in another ObservableCollection

I have an ObserveableCollection which contains another ObserveableCollection. In my WPF i set a binding to Persons.Lectures. My problem is now when i change any value in the "lectures" collection, the "persons" collection doesn't notify that und my binding neither. Is this generally a problem when using an ObserveableCollection into another ObserveableCollection ?

How can i solve this, so that my binding will react ?

Upvotes: 3

Views: 1503

Answers (3)

Vinit Sankhe
Vinit Sankhe

Reputation: 19885

Although I (and WPF in general) prefer ObservableCollection, I would suggest you to use BindingList for this "specific" puspose.

As far as I know, BindingList in another BindingList would propagate the collection changed notifications up the hierarchy without any extra plumbing.

Try and let me know.

Upvotes: 0

jdmcnair
jdmcnair

Reputation: 1315

I'm not completely clear on your scenario here. Is "Persons" an ObservableCollection? Yet, you're saying that it has a "Lectures" property, which isn't the case on a standard ObservableCollection. Is this a new class inherited from ObservableCollection that has a "Lectures" property that is also an ObservableCollection?

I'm guessing that you've got an ObservableCollection of Person objects, which themselves have an ObservableCollection of Lectures. Is that the case? If so, maybe you're just constructing your Binding incorrectly.

Upvotes: 0

slugster
slugster

Reputation: 49974

The ObservableCollection implements INotifyCollectionChanged, which notifies you of changes (additions, change of order, etc) to the collection itself.

If you want your bindings to update then the actual objects contained in the ObservableCollection must implement INotifyPropertyChanged. You may notice that the collection does implement that interface too, but that is to notify of changes to the properties of the collection object itself, NOT changes to the properties of its contents.

Upvotes: 3

Related Questions