3

I have a user control. there I want to maintain a collection as a dependency property. Suppose that property is bound to a collection which implements INotifyCollectionChanged.

Now suppose the collection got added or removed with some item how can i listen to that change in the user control.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Mintu
  • 31
  • 2

1 Answers1

3

You can't listen to it, since CollectionChanged is not a RoutedEvent.

WPF will automatically add items to the control, for example an ItemsControl when an object has been added to your list.

I found ObservableCollection<T> very useful, since it takes away a lot of work you had to do when using INotifyCollectionChanged, but that is just a suggestion.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • If i take observable collection as the dependency property then the binded objects must be an observable collection. My problem is, I want to do somthing on User control when the collection is modified. – Mintu May 06 '14 at 13:39
  • @user3608101: Then you have to rely on code. Just hook up the event handler in the xaml.cs file. – Patrick Hofman May 06 '14 at 13:40
  • on what event. that is what my question. – Mintu May 06 '14 at 13:45