WPF 中是否有 PagedCollectionView 的实现?它存在于 Silverlight 中,但不在 WPF 中。
如果没有,实现这一点的最简单方法是什么?
WPF 中是否有 PagedCollectionView 的实现?它存在于 Silverlight 中,但不在 WPF 中。
如果没有,实现这一点的最简单方法是什么?
您可以简单地从Silverlight中获取代码并在您的 WPF 项目中使用它。
或仅使用 CollectionView 类并“双重过滤”您的收藏
在这里找到的解决方案:自己的 CollectionView 用于分页、排序和过滤
为了您的方便,我在这里粘贴了代码片段:
// obtenir la CollectionView
ICollectionView cvCollectionView = CollectionViewSource.GetDefaultView(this.Suivis);
if (cvCollectionView == null)
return;
// filtrer ... exemple pour tests DI-2015-05105-0
cvCollectionView.Filter = p_oObject => { return true; /* use your own filter */ };
// page configuration
int iMaxItemPerPage = 2;
int iCurrentPage = 0;
int iStartIndex = iCurrentPage * iMaxItemPerPage;
// déterminer les objects "de la page"
int iCurrentIndex = 0;
HashSet<object> hsObjectsInPage = new HashSet<object>();
foreach (object oObject in cvCollectionView)
{
// break if MaxItemCount is reached
if (hsObjectsInPage.Count > iMaxItemPerPage)
break;
// add if StartIndex is reached
if (iCurrentIndex >= iStartIndex)
hsObjectsInPage.Add(oObject);
// increment
iCurrentIndex++;
}
// refilter
cvCollectionView.Filter = p_oObject =>
{
return hsObjectsInPage.Contains(p_oObject);
};