Introduced
Re-imagine the bindings of Windows 8 Store Apps
Provides data for incremental loading of listviewbase by implementing the Isupportincrementalloading interface
Example
Implements the Isupportincrementalloading interface to provide data for incremental loading of listviewbase
Binding/myincrementalloading.cs
* * Demonstrates how to implement the Isupportincrementalloading interface to provide data for incremental loading of listviewbase * isupportincrementalloading-for support of incremental loading * Hasmoreitems-Is there more data * iasyncoperation<loadmoreitemsresult> Loadmoreitemsasync (UINT count)-asynchronously loading a specified number of
Data (incremental load) * * Loadmoreitemsresult-the result of the incremental load * Count-the amount of data actually loaded */using System;
Using System.Collections.Generic;
Using System.Collections.ObjectModel;
Using System.Runtime.InteropServices.WindowsRuntime;
Using System.Threading.Tasks;
Using Windows.foundation;
Using Windows.UI.Core;
Using Windows.UI.Xaml;
Using Windows.UI.Xaml.Data; Namespace Xamldemo.binding {public class myincrementalloading<t>: Observablecollection<t>, isupportinc
rementalloading {//whether the private bool _isbusy = False is being loaded asynchronously; Provides the Func//first parameter of the data: The starting index of the incremental load; the second parameter: The amount of data to be fetched; third parameter: Gets the data collection private func<int, int, list<t>>
_funcgetdata; Maximum amount of data available private UINT _totAlcount = 0; <summary>///Constructor///</summary>///<param name= "totalcount" > Maximum amount of data < /param>///<param name= "Getdatafunc" > Provide data func</param> public myincrementalloading (UINT t
Otalcount, Func<int, int, list<t>> getdatafunc) {_funcgetdata = Getdatafunc;
_totalcount = TotalCount;
///<summary>///Do you have more data///</summary> public bool Hasmoreitems {get {return this. Count < _totalcount; }///<summary>///asynchronous Load data (incremental load)///</summary>///<param N Ame= "Count" > amount of data to load </param>///<returns></returns> public IASYNCOPERATION<LOADMO Reitemsresult> Loadmoreitemsasync (UINT count) {if (_isbusy) {throw New INVALIDOPERATIONEXCEPtion ("Busy, ignore you first");
} _isbusy = true;
var dispatcher = Window.Current.Dispatcher;
return Asyncinfo.run (token) => task.run<loadmoreitemsresult> (
Async () => {try {
Simulate long time task await task.delay (1000); Incremental load starting index var startIndex = this.
Count; Await dispatcher.
Runasync (Coredispatcherpriority.normal, () =>
{//Get incremental data through Func
var items = _funcgetdata (StartIndex, (int) count); foreach (Var item inItems) {this.
ADD (item);
}
}); Count-The amount of data actually loaded return the new Loadmoreitemsresult {Count = (UINT) this.
Count};
finally {_isbusy = false;
}}, token)); }
}
}