c# - Populating GridView with data from XML file -


so, in windows 8 tablet application, have gridview following property:

    <grid>         <gridview itemssource="{binding source={staticresource manager}, path=teststrings}" />     </grid> 

that links property teststrings in 1 class.

public list<string> teststrings     {                 {             list<location> locations = getlocations();               list<string> teststrings = new list<string>();              (int = 0; < locationlist.count; i++)             {                 teststrings.add(locationlist[i].name);             }              return teststrings;         }     }      public async task<list<location>> getlocations()     {         return await xmlparser.getlocations();     } 

if populate string list values , return it, gridview displays values, no problem. however, issue need call async method. of data coming xml file. access xml file, have pull file storage, far know requires me await. here, method:

public async task<list<location>> getlocations()     {         storagefolder storagefolder = applicationdata.current.localfolder;         storagefile file = await storagefolder.getfileasync("main.xml");         xmldocument xmldoc= await xmldocument.loadfromfileasync(file);         xdocument xml = xdocument.parse(xmldoc.getxml());          list<location> locationlist =             (from _location in xml.element("apps").elements("app").elements("locations").elements("location")              select new location              {                  name = _location.element("name").value,              }).tolist();          return locationlist;     } 

as see, await twice forces me make async method, means methods call must async. however, binding property in xaml requires access property, cannot async.

i feel missing something. i've moved on android start programming in windows 8, lot of new me. surely, displaying data files ui common task. best way handle it?

try changing type of list list observablecollection, , see if fixes things. observation of async behavior spot on: modifications list not trigger notification binding engine anything's changed, , change happening unknown time later. notification occur when use observablecollection.


Comments