有没有办法暂停
ObservableCollection
的NotifyCollectionChanged
事件?我想到了以下方式:public class PausibleObservableCollection<Message> : ObservableCollection<Message>
{
public bool IsBindingPaused { get; set; }
protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (!IsBindingPaused)
base.OnCollectionChanged(e);
}
}
这确实暂停了通知,但显然被留下(但仍被添加)的项目在NotifyCollectionChangedEventArgs
中,因此当我重新启用通知时,它们不会传递给绑定的DataGrid。
我需要自定义一个集合实现来控制这个方面吗?