I searched internet for paging user control code but could not find anyone which satisfy below condition :
Note : I fetched all rows in one service call and store the collection in parent viewmodel (lets say ObservableCollection objMyList).
All paging logic in PagingControlVM not in xaml.cs file
No tightly couple binding between paging control and parent control like I just drop the pagecontrol in parent page and create only one dependency property(lets say MyDepProp) in PagingControl.xaml.cs file .
When PagingControl drop in ParentControl , I use this dependency property to bind with ObservableCollection objMyList (I succeed so far but how I can get the value of dependency property in PagingControlVM. I want to get the value of MyDepProp in new collection in PagingControlVM ).
If I am doing wrong please tell me good approach.
Thanks for your help
First of all, there is no need of PagingControlVM
here. What you need is to have a own class
inherited from CollectionView
(say PagingCollectionView
) where all your paging logics should be there. Then, you have to create an instance of PagingCollectionView
as objMyList
in your parent viewmodel that can be passed to the UserControl
's ItemsSource
.
For more info: Own CollectionView for paging, sorting and filtering
Edit based on your comment:
If you want to change the list, changes will be notified as we have implemented the PagingCollectionView
from CollectionView
.
private ObservableCollection<string> _objMyList ;
public ObservableCollection<string> objMyList
{
get { return _list; }
set { _list = value; }
}
private PagingCollectionView _pagingsource;
public PagingCollectionView PagingSource
{
get
{
if(_pagingsource == null)
_pagingsource = new PagingCollectionView(List, 5);
return _pagingsource;
}
}
Bind the PagingSource
to the UI. You can always change the objMyList
that will be notified to UI.
Hope that helps.