我對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)以獲得更好的幫助。 –