Remove an item from an ObservableCollection in a CollectionChanged event handler

后端 未结 5 641
逝去的感伤
逝去的感伤 2021-02-02 01:13

I\'m hoping to be able to reject some items after they have been added to an ObservableCollection. I am not able to subclass the ObservableCollection or use any sort of view, s

5条回答
  •  孤城傲影
    2021-02-02 01:58

    Used this in the oncollectionchanged and it works (WPF and MVVM example):

    new System.Threading.Thread(t =>
    {
      Application.Current.Dispatcher.Invoke((Action)delegate
      {
        OnHoldMessages.Add(_selectedOnHoldMessage);
        RaisePropertyChanged(propertyName: "OnHoldMessages");
      });
    }).Start();
    

提交回复
热议问题