I am working on a project in WPF using the MVVM Light framework. I have a DataGrid
that is bound to an ObservableCollection
. As of no
You shouldn't have public setters on lists for your objects. You should rather set ut up in your constructor
public MyClass(){
_masterWorkerList = new ObservableCollection<Worker>();
_masterWorkerList.CollectionChanged += OnCollectionChanged;
}
public ObservableCollection<Worker> MasterWorkerList
{
get { return _masterWorkerList; }
}
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e){
System.Windows.MessageBox.Show("Firing");
//RaisePropertyChanged(() => MasterWorkerList);
}
The CollectionChanged
event is called when you Add
something to the ObservableCollection. If you need more ingrained control you can inherit from the ObservableCollection
and override the AddItem
and RemoveItem
methods.