I need to remove an item from an ObservableCollection by itself.
Is it possible doing something like this?
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()
Note: I don’t want to use Items.Remove(_Item) method.
Thank you…
All you need is for each Item to have a reference to its owner ObserableCollection
Then you can do
You will also have to handle cases where items are added multiple collection.