Reputation: 906
SelectedObjects.CollectionChanged += (s, e) =>
{
Console.WriteLine(e.NewItems.Count);//prints out 1 if a new item is added
};
one thing i am not sure of is why e.OldItems and e.NewItems are collections?
if i add multiple items per second the event gets fired foreach item and the output is always 1 meaning that it gets fired multiple times, but is there a way to delay the event firing, for example after 5 seconds of the change so that i could get every change in those 5 seconds in the e.OldItems or the e.NewItems?
Upvotes: 3
Views: 338
Reputation: 38825
No. The point of an observable collection is to raise the event when it is modified. Whilst in your use-case it is desirable to be notified after a set amount of time, it is not every use-case and would over-complicate the class.
What you could do is wrap the observable collection in to a custom class that you create (e.g. DelayedObservableCollection<T>
, and that - in conjunction with a timer -, raises its' own event when items are added/modified, and then no items are added/modified after a specified time, or more than 'x' items are added/modified.
Upvotes: 5