考慮這個代碼(genericised例如目的類型名稱):什麼導致使用自定義排序重新排序其項目的WPF ListCollectionView?
// Bound to ListBox.ItemsSource
_items = new ObservableCollection<Item>();
// ...Items are added here ...
// Specify custom IComparer for this collection view
_itemsView = CollectionViewSource.GetDefaultView(_items)
((ListCollectionView)_itemsView).CustomSort = new ItemComparer();
當我設置CustomSort
,因爲我希望集合排序。
但是,我需要數據在運行時重新排序以響應Item
上屬性的更改。 Item
類派生自INotifyPropertyChanged
,我知道該屬性觸發正確,因爲我的數據模板更新屏幕上的值,只有排序邏輯沒有被調用。
我也試着提高INotifyPropertyChanged.PropertyChanged
傳遞一個空字符串,看看是否一個通用的通知會導致排序啓動。沒有香蕉。
編輯迴應肯特的建議我認爲我會指出,使用這種具有相同的結果,即收集各種各樣一次,但不重新排序的數據更改排序的項目:
_itemsView.SortDescriptions.Add(
new SortDescription("PropertyName", ListSortDirection.Ascending));
鏈接已經死了新的:http:// drwpf .com/blog/2008/10/20/itemscontrol-e-is-for-editable-collection/ – Gman 2013-04-04 15:00:09