0

Can one bind to a List, such that when any of the list elements get changed, the target gets notified? I I want to a dependency property to the list with a multivalue converter in which I do something with the list each time any of the elements change or new elements get added.

mihajlv
  • 2,275
  • 4
  • 36
  • 59

1 Answers1

1

There is an interface that lists can implement, INotifyCollectionChanged, which is used to notify that the elements it contains have changed. The framework class ObservableCollection implements this interface.

If you need to handle changes from any element in the collection, you will find an implementation here:

ObservableCollection that also monitors changes on the elements in collection

Community
  • 1
  • 1
ColinE
  • 68,894
  • 15
  • 164
  • 232
  • 1
    But wont notify when "the list elements get changed" only when the list itself is changed. – Magnus Jan 08 '12 at 22:00
  • True, if you need this functionality, you will have to write it yourself. – ColinE Jan 08 '12 at 22:02
  • ObservableCollection only notifies when the _collection_ changes--add, remove, etc. NOT when a property of an object in the collection changes – Muad'Dib Jan 08 '12 at 22:03
  • @ColinE How do I go about writing such functionality? – mihajlv Jan 08 '12 at 22:08
  • 1
    Yes, I know. I have written a class that extends ObservableCollection to add this functionality in the past. It is in the Visiblox charts product: http://www.visiblox.com/static/releases/1.8.1/Docs/html/3ca2d7ac-7a0c-1dd9-e08a-50fad83d4da7.htm as I said, you have to write this yourself! – ColinE Jan 08 '12 at 22:09
  • @mihajlv I have just found an implementation on SO - see the updated answer. – ColinE Jan 08 '12 at 22:10
  • @ColinE Thank you I'll take a look at the link, and let you know of the outcome. Thanks again. – mihajlv Jan 08 '12 at 22:11