List<string> INotifyPropertyChanged event List<string> INotifyPropertyChanged event wpf wpf

List<string> INotifyPropertyChanged event


You should use ObservableCollection<string> instead of List<string>, because unlike List, ObservableCollection will notify dependents when its contents are changed.

And in your case I'd make _includeFolders readonly - you can always work with one instance of the collection.

public class DatabaseRecord : INotifyPropertyChanged {    private readonly ObservableCollection<string> _includeFolders;    public ObservableCollection<string> IncludeFolders    {        get { return _includeFolders; }    }    public DatabaseRecord()    {        _includeFolders = new ObservableCollection<string>();        _includeFolders.CollectionChanged += IncludeFolders_CollectionChanged;    }    private void IncludeFolders_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)    {        Notify("IncludeFolders");    }    ...}


The easiest way to make WPF's list binding work is to use a collection that implements INotifyCollectionChanged. A simple thing to do here is to replace or adapt your list with an ObservableCollection.

If you use ObservableCollection, then whenever you modify the list, it will raise the CollectionChanged event - an event that will tell the WPF binding to update. Note that if you swap out the actual collection object, you will want to raise the propertychanged event for the actual collection property.


Your List is not going to fire the NotifyPropertyChanged event automatically for you.

WPF controls that expose an ItemsSource property are designed to be bound to an ObservableCollection<T>, which will update automatically when items are added or removed.