Explanation
There is a collection type in C # that notifies changes made to the list through events, at ObservableCollection .
With it, you can assign a method in the CollectionChanged
event to receive change notifications in the list and also use the PropertyChanged
event to receive notification of changes in the properties.
Example
using System;
using System.Collections.ObjectModel;
namespace ObservableCollectionExample
{
class Program
{
static void Main(string[] args)
{
ObservableCollection<string> list = new ObservableCollection<string>();
list.CollectionChanged += List_CollectionChanged;
list.Add("Teste 1");
list.Add("Teste 2");
}
private static void List_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
Console.WriteLine("A lista foi alterada.");
}
}
}
See working at DotNetFiddle