c# - Windows phone proper way to display collection of items -


i have xml file items , i'm deserializing them observablecollection<usercontrol> , want put itemscontrol own layout.

now i've created own usercontrol handle deserialized data layout , observablecollection binded itemscontrol if want display more 5-10 items app if getting unresponsive while.

how can avoid freezes? should use datatemplate within itemscontrol or other ideas? i'm wondering how done in apps twitter or reddit have many entries , working quite nice. have searched reddit/twitter app source how have implemented it, without success.

edit:

xaml

  <scrollviewer>         <itemscontrol x:name="items" itemssource="{binding}">             <itemscontrol.itemspanel>                 <itemspaneltemplate>                     <virtualizingstackpanel />                 </itemspaneltemplate>             </itemscontrol.itemspanel>         </itemscontrol>     </scrollviewer> 

c#

    public mainpage()     {         this.initializecomponent();         items.datacontext = _items;     }      public observablecollection<my_item> _items = new observablecollection<my_item>(); 

adding items

   (int = 0; < 40; i++)    {        _items.add(new my_item());    } 

my_item own usercontrol 2 small images, few buttons , single textblock.

you should use listview has virtualizing panel displaying items default:

<listview itemssource={binding items} >      <listview.itemtemplate>             <datatemplate>                    <!-- here goes item layout -->             </datatemplate>      </listview.itemtemplate> </listview> 

maybe 1 reason app "hanging" if deserializing/parsing xml file on ui thread, if xml file large, solution problem need xml parsing on background thread:

task.run(() =>  {     var items = parsexml(); }); 

after edit:

1) don't wrap itemscontrol inside scrollviewer, because break virtualization. itemscontrol has own scrollviewer there no need of additional one.

if on windows phone 8.1 runtime, use itemsstackpanel instead of virtualizingstackpanel.

2) recommended lists many items use datatemplates instead of filling ui elements. rather create data template user control:

<datatemplate>    <myusercontrol/> </datatemplate> 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -