我正在将ItemsControl绑定到CollectionViewSource。以下是代码:
this.Trucks = new ObservableCollection<Truck>();
foreach (var truck in DataRepository.Trucks.Where(t => t.ReadyDate.Date.Equals(this.Date)))
{
this.Trucks.Add(truck);
}
this.TrucksSource = new CollectionViewSource { Source = this.Trucks };
this.TrucksSource.SortDescriptions.Add(new SortDescription("ReadyAddress.Region.RegionNumber", ListSortDirection.Ascending));
this.TrucksSource.SortDescriptions.Add(new SortDescription("TruckId", ListSortDirection.Ascending));
当我最初进行绑定时,排序是有效的。当我向ObservableCollection添加项目时,它会被插入到正确的位置,这很好。但是当我更改按其排序的属性时,此项未在列表中“移动”。
ReadyAddress.Region.RegionNumber
正确地引发了 INotifyPropertyChanged,我在绑定字段中看到了它,但顺序没有改变。我是否期望不应该发生的事情,或者有更好的方法来处理这种情况?