我对CollectionChanged
事件的ObservableCollection<T>
对象的处理程序,并不能弄清楚如何使用NotifyCollectionChangedEventArgs
检索包含IList
的事件内的项目。NotifyCollectionChangedEventArgs项目无法访问
添加到集合中的新项目位于NewItems
属性,IList
对象中。 Intellisense不会允许我访问.Item[Index]
(我应该能够根据文档),也不能将NewItems
列表转换为局部变量(根据调试,NewItems
列表是System.Collections.ArrayList.ReadOnlyList
,它似乎不是作为在MSDN中无障碍课程。)
我在做什么错?
实施例:
private void ThisCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
Item I = e.NewItems._________;//<<<<<cannot access any property to get the item
var j = e.NewItems;//System.Collections.ArrayList.ReadOnlyList, see if you can find in the MSDN docs.
IList I1 = (IList) e.NewItems;//Cast fails.
IList<Item> = (IList<Item>)e.NewItems.________;//<<<<<<<Can't make this cast without an IList.Item[Index] accessor.
var i = j[0]; //null
var ioption = j.Item[0]; //no such accessor
string s = (string)i; //null
}
这个例子是保持事物尽可能通用,并且仍然会失败。
您应该提供[最小,完整和可验证示例](http://stackoverflow.com/help/mcve)以获得更好的帮助。 –