Reputation: 11091
I have a list view that has a column databound to a list.Count see below:
<ListView.View>
<GridView>
<GridViewColumn Header="Contacts" DisplayMemberBinding="{Binding Path=Contacts.Count}"/>
<GridViewColumn Header="Notes" DisplayMemberBinding="{Binding Path=Notes.Count}"/>
</GridView>
</ListView.View>
The List implements INotifyCollectionChanged. But when I add an item to the list the listview column does not get refreshed. am I doing something wrong in my binding? I can do the following:
void _Contacts_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged("Contacts");
}
Which basically raises the PropertyChanged event of the collection. This forces wpf to rebind, but I would rather not have an abundance of events flying through my code(especially the unnecessary ones).
Any ideas?
Upvotes: 1
Views: 2093
Reputation: 4963
Alternatively, you can derive from ObservableCollection instead. It has all the change notification code built into it and could save you some time in the long run.
Upvotes: 1
Reputation: 27065
The problem is that while you raise a property changed for Contacts, you do not raise an event for the Count property..
You can solve this with
OnPropertyChanged("Count")
in your list, since your list implements the INotifyPropertyChanged interface...
Upvotes: 1