windows phone 7 - Lazy loading list box, in a panorama page -


i wanted add lazy loading list box(load content when swipe) in panorama page in 1 of windows phone 7 applications. using pivot page. referred this link

but not working panorama page.
can please me?

okay, you're going need 1 of 2 things: use bcl async package (basically adds async tasks , such wp7) or use background worker. highly suggest bcl async package, it's easy on nuget.

now, in viewmodel (you using mvvm, yes?) property it's bound to, let's call items should return observablecollection of item type need. now, here's magic happens. in getter of property, return new collection , use task fill it. this:

public observablecollection<object> items {         {         observablecollection<object> retcollection = new observablecollection<object>();         fillcollection(retcollection);         return retcollection;     } }  public async void fillcollection(observablecollection<object> collectiontofill) {     task.factory.startnew(() =>     {         foreach(object objecttoadd in collectionimgettingthisdatafrom)         {             // using dispatcher              // sure pop ui thread.             deployment.current.dispatcher.begininvoke(                 () => collectiontofill.add(objecttoadd));         }     } } 

because fillcollection async, method continue , return current collection. on thread, task that's created find data add, push ui thread add collection. way, you'll able lazy load data when ask it, without blocking ui thread. if turns out it's still making ui slow, can add line:

await taskex.delay(25); // time in milliseconds. ,                          // take long time load list,                         // little , still bog down ui. 

at end of foreach block, not in dispatcher invokation.

happy coding!


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -