Remove one Item in ObservableCollection

后端 未结 3 736
情话喂你
情话喂你 2021-01-04 05:34

I have some method like:

public void RemoveItem(ObservableCollection collection, SomeClass instance)
{
    if(collection.Contains(instance))         


        
3条回答
  •  时光取名叫无心
    2021-01-04 05:57

    If the item you intend to remove has something like a code/id you could compare to other item, you could do something in the lines of:

    foreach (var item in itemSet)
    {
      if (item.ItemID == itemToCompareTo.ItemID)
      {
        itemSet.Remove(item);
        break;
      }
    }
    

提交回复
热议问题