I want to bind to the Count/amount of items within my DataContext.
I have an object, lets say person which has a List
as a property. I would
In my case, Robert's answer got me really close to what I was after. However, I'm adding many items to the list from a service call, and didn't want the event firing for each item. To this end, I took advantage of functionality already built into BindingList
:
public class BindingListNotifyCount : BindingList, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected override void OnListChanged(ListChangedEventArgs e)
{
base.OnListChanged(e);
RaisePropertyChanged("Count");
}
protected void RaisePropertyChanged([CallerMemberName]string propertyName = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
Then I simply use it as:
displayItems.RaiseListChangedEvents = false;
serviceItems.ForEach(item => displayItems.Add(item));
displayItems.RaiseListChangedEvents = true;
displayItems.ResetBindings();