我有一个问题。我有一个非常简单的分页机制,它与WPF按钮和数据网格相结合,看起来像:
public CatalogViewModel()
{
this._catalog = new CatalogContexct();
DbQuery<Candidate> candidatesValues = this._catalog.Candidates.Include("commendation");
this._totalItems = candidatesValues.Count();
this._candidates = candidatesValues.ToArray()
.OrderBy(c => c.Firstname).Skip(this.Start).Take(this._itemCount).ToList();
this._filters = new Dictionary<string, Predicate<Candidate>>();
var candidates = new ListCollectionView(this._candidates);
this.CandidateView = CollectionViewSource.GetDefaultView(candidates);
this.FirstameCommand = new RelayCommand(FilterFirstname, param => this._canExecute);
this.LastnameCommand = new RelayCommand(FilterLastname, param =>
CandidateView.Filter = FilterCandidates;
//should be something else to limit view to page so filter can be done on whole source not only part of it like above
}
但正如我所描述的,我需要在paginatio之前过滤值或者对此过滤的值进行分页.CandidateView = CollectionViewSource.GetDefaultView(候选者);
有可能吗?
如果我手动过滤集合并将该值传递给视图,我将是可行的,但我想知道是否有更简单的方法来手动操作数据。
答案 0 :(得分:1)
您可以使用用于过滤ICollectionView
的相同谓词来过滤源集合:
this._candidates = candidatesValues.Where(FilterCandidates).OrderBy(c => c.Firstname).Skip(this.Start).Take(this._itemCount).ToList();
然后您根本不需要过滤甚至使用ICollectionView。您可以直接绑定到已过滤和已分页的源集合。