Should I bind to ICollectionView or ObservableCollection

前端 未结 5 613
失恋的感觉
失恋的感觉 2020-11-29 19:44

Should one bind DataGrid to the

ICollectionView = CollectionViewSource.GetDefaultView(collection)

or to the

Observabl

5条回答
  •  既然无缘
    2020-11-29 20:24

    ObservableCollection implements INotifyCollectionChanged and will notify the UI when the items in the collection have been changed.

    ICollectionView will give you the ability to filter, sort, or group the collection in addition to propogating INotifyCollectionChanged events if the underlying collection implements it.

    Either type works well with MVVM as long as you bind to it. Use ICollectionView when you need sorting, filtering, or grouping. Use ObservableCollection directly when you don't.

提交回复
热议问题