Windows 8 Store Apps Learning (54) Binding: Incrementally loading Data

Source: Internet
Author: User
Tags bool count

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&LT;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)); }
    }
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.