When Clearing an ObservableCollection, There are No Items in e.OldItems

前端 未结 20 1629
不知归路
不知归路 2020-11-30 00:27

I have something here that is really catching me off guard.

I have an ObservableCollection of T that is filled with items. I also have an event handler attached to t

20条回答
  •  有刺的猬
    2020-11-30 00:40

    To keep it simple why don't you override the ClearItem method and do whatever you want there ie Detach the items from the event.

    public class PeopleAttributeList : ObservableCollection,    {
    {
      protected override void ClearItems()
      {
        Do what ever you want
        base.ClearItems();
      }
    
      rest of the code omitted
    }
    

    Simple, clean, and contain within the collection code.

提交回复
热议问题