Event publication/subscription and INotifyPropertyChanged

Jul 22, 2008 at 4:24 PM
I have following scenario.
1) StudentView has a listbox to display student names. DataContext of the view is bound to StudentModel within same module. StudentModel has a property StudentList returning List<Student>.
2) The property StudentList in turn gets its records from StudentDataService. StudentDataService publishes ListChanged event to notify changes.
3) StudentModel is a subscriber to ListChanged event. StudentModel also implements INotifyPropertyChanged interface to notify bound controls.

Stepping through the code, event publication/subscription works perfect. While in debugger, I can even see the conents of StudentList property being refreshed but the contents of ListBox on StudentView (.xaml) do not change. My implementation of INotifyPropertyChanged is fine since I have used it at other places successfully.

Any clues, what I am missing here.
Jul 22, 2008 at 7:05 PM
One quick suggestion - Try replacing List<Student> with System.Collections.ObjectModel.ObservableCollection<Student>.  You should bind your ListBox to a collection of this type in WPF, when the collection is changing.

If this doesn't work, post your code and we'll see what's going on.
Jul 22, 2008 at 7:30 PM
Bull's eye. Thanks jwalklin. Changing List to ObservableCollection fixed the problem. I still have to go back and check several other places where I was using List<T> for similar situations and compare but for now that's all I needed.