0
我需要自己從ObservableCollection中移除項目。 是否有可能做這樣的事情?如何創建具有自我移除方法的ObservableCollection項目
public class Item
{
public Item()
{
// Constructor
}
public string ID
{
get;
set;
}
public void Remove()
{
// I need to write some code here if it is possible
}
}
//---------- this part is in a ClickEvent i.e.
ObservableCollection<Item> Items = new ObservableCollection<Item>();
Item _Item = new Item() { ID = 1 }
Items.Add(_Item);
_Item.Remove()
注:我不想使用Items.Remove(_Item)方法。
謝謝...
感謝您的快速響應。 項目集合由DataContract解串器動態填充。在這種情況下,我不知道如何在物品中引用物品。 – kizanlik 2012-07-22 14:53:34
您可以有一個[OnDeserializedAttribute](http://msdn.microsoft.com/en-us/library/system.runtime.serialization.ondeserializedattribute.aspx)方法來設置所有者 – 2012-07-22 14:55:50
謝謝。那是我需要的。 – kizanlik 2012-07-22 15:00:54