Paged Collection View in WPF

时光总嘲笑我的痴心妄想 提交于 2019-12-01 02:24:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!