0
您是否知道增量集合的備選加載方式,如wpf ISupportIncrementalLoading?增量集合爲Silverlight加載/ ISupportIncrementalLoading
您是否知道增量集合的備選加載方式,如wpf ISupportIncrementalLoading?增量集合爲Silverlight加載/ ISupportIncrementalLoading
,我看到沒有任何答案;( 對於原因,我將張貼在這裏我實現 庫仍處於BETA版本,並請,如果您有任何問題請點擊這裏發送您的問題
/// P.Zh.
public class IncrementalLoadingCollection<T, TT> : ObservableCollection<TT>, ISupportIncrementalLoading
where T : IIncrementalSource<TT>, new()
{
private T source;
private int itemsPerPage;
private bool hasMoreItems;
private int currentPage;
public IncrementalLoadingCollection(int itemsPerPage = 20)
{
this.source = new T();
this.itemsPerPage = itemsPerPage;
this.hasMoreItems = true;
}
public bool HasMoreItems
{
get { return hasMoreItems; }
}
public async Task<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
{
var task = Task.Factory.StartNew(async() =>
{
uint resultCount = 0;
var result = await source.GetPagedItems(null, currentPage++, itemsPerPage);
if (result == null || result.Count() == 0)
{
hasMoreItems = false;
}
else
{
resultCount = (uint)result.Count();
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
foreach (TT item in result)
this.Add(item);
});
}
return new LoadMoreItemsResult() { Count = resultCount };
}
// ,CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default
).Unwrap();
return task.Result;
}
}
public interface IIncrementalSource<T>
{
/// <summary>
/// Get Chunk of data in specific interval from a colection
/// </summary>
/// <param name="o">custome object</param>
/// <param name="pageIndex">uint start position</param>
/// <param name="pageSize">uint end position</param>
/// <returns>Result is chunk</returns>
Task<IEnumerable<T>> GetPagedItems(object o, int pageIndex, int pageSize);
bool HasMoreItems { get; set; }
}
public interface ISupportIncrementalLoading
{
bool HasMoreItems { get; }
Task<LoadMoreItemsResult> LoadMoreItemsAsync(uint count);
}
public interface IIncrementalResult<T>
{
IEnumerable<T> Items { get; }
int VirtualCount { get; }
}
public struct LoadMoreItemsResult
{
public uint Count { get; set; }
}
。
當我準備好調用示例時,我將在這裏發佈新評論。 – Petar