How do I trigger an event when a List is changed?

2

I wanted to know if it is possible, and if so, how to trigger an event when a List is changed, for the following changes:

  • An element is removed;
  • An element is added;
  • An element has its index changed;

Is there any way to trigger an event when this occurs?

    
asked by anonymous 21.05.2015 / 17:09

1 answer

3

Yes, but it is not exactly using List<> . Use instead ObservableCollection<T> .

Basically, the class has two events that do what you need , but you would only use CollectionChanged for the three cases.

Another way would be to use dynamic proxy, but it would only be recommended to intercept cases where ObservableCollection can not act.

    
21.05.2015 / 17:30