I am attempting to get some custom objects from the CollectionChanged
event of a collection which implements INotifyCollectionChanged
.
MyControl_MyCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if(e.Action == NotifyCollectionChangedAction.Add)
{
lock(e.NewItems.SyncRoot)
{
var myItems = e.NewItems.OfType<MyType>();
if(myItems.Any())
{
//do stuff
}
}
}
}
The problem I am facing is that myItems
always says "Enumeration yielded no results".
Expanding on debug e.NewItems.SyncRoot
shows the following:
e.NewItems.SyncRoot | {object[1]}
|-[0] | {System.Linq.Enumerable.WhereSelectListIterator<MyType, IMyInterface>}
| |-base ...
| |-Non-public members
| |-Results View | Expanding the Results View...
| |-[0] | MyType
So clearly the data is there. What is the method for retrieving this data?
.Any()
instead of.Count() > 0
. You don't care how many items you have (at that point), so why bother counting them all? – Stephaniastephanie