using System.Collections.ObjectModel;
using System.Windows.Data;
using Microsoft.IT.Security.UI.Framework.Commons;
/// <summary>
/// 1.0.2
/// </summary>
public abstract class ServerPagerViewModel : MyViewModelBase
{
private ObservableCollection<int> pageCollection = new ObservableCollection<int>();
private bool isCreatingPagerData = false;
private int pageIndex = 0;
public int PageIndex
{
get
{
return pageIndex;
}
set
{
if (!isCreatingPagerData)
{
pageIndex = value;
base.RaisePropertyChanged(this, "PageIndex");
}
}
}
private int pageSize = 6;
public virtual int PageSize
{
get
{
return pageSize;
}
set
{
pageSize = value;
base.RaisePropertyChanged(this, "PageSize");
}
}
private PagedCollectionView pagerSource;
public PagedCollectionView PagerSource
{
get
{
return pagerSource;
}
set
{
pagerSource = value;
base.RaisePropertyChanged(this, "PagerSource");
}
}
public ServerPagerViewModel()
{
this.PagerSource = new PagedCollectionView(pageCollection);
this.PagerSource.PageSize = this.PageSize;
}
protected abstract void OnPageIndexChanged();
/// <summary>
/// Called when [pager bind].
/// </summary>
/// <param name="totalCount">The total count.</param>
protected void OnPagerBind(int totalCount)
{
isCreatingPagerData = true;
this.pageCollection.Clear();
for (int i = 0; i < totalCount; i++) this.pageCollection.Add(i);
base.RaisePropertyChanged(this, "PageIndex");
isCreatingPagerData = false;
}
/// <summary>
/// Gets the page index changed.
/// </summary>
public DelegateCommandBase PageIndexChangedCommand
{
get
{
return new DelegateCommandBase((parameter) =>
{
if (!isCreatingPagerData)
{
OnPageIndexChanged();
}
});
}
}
}