问题
Is there an implementation of PagedCollectionView in WPF around? It exists in Silverlight but isn't in WPF.
If there isn't, what would be the simplest way to implement this?
回答1:
You can simply take the code from the Silverlight one and use that in your WPF project.
回答2:
Or use only the CollectionView class and "double filter" your collection
solution found here: Own CollectionView for paging, sorting and filtering
I've pasted the code snipet here for your convinience:
// 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);
};
来源:https://stackoverflow.com/questions/8003845/paged-collection-view-in-wpf