Reputation: 31795
I have a public property called Items, It's a List. I want to tell when it's been altered. How can I do this?
For example, if Items.Add is called, I want to be able to then call UpdateInnerList.
How can I do this?
Upvotes: 0
Views: 84
Reputation: 10008
It supports a CollectionChanged event which should be what you need.
Upvotes: 2
Reputation: 3371
Can you use the ObservableCollection
?
http://msdn.microsoft.com/en-us/library/ms668604.aspx
Upvotes: 5
Reputation: 120480
How about creating a List subclass and overriding the Add method?
void Main()
{
var x=new MySpecialList<string>();
x.Add("hello");
}
class MySpecialList<T>:List<T>
{
public new void Add(T item)
{
//special action here
Console.WriteLine("added "+item);
base.Add(item);
}
}
Upvotes: 2