Paged Collection View in WPF

大兔子大兔子 提交于 2019-12-01 04:47:59

You can simply take the code from the Silverlight one and use that in your WPF project.

Sam L.

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