c# - How to bind image in Gridview using xml parsing in windows metro app -
c# - How to bind image in Gridview using xml parsing in windows metro app -
i'm working on first windows 8 app. i'm trying display gridview populated image , image description. want info xml file created. found itemsource property of gridview , seek bind xml file can't this.
please tell me right way task. thanx
you can't bind xml file straight gridview.itemssource
, need parse first object. i'd create class info displayed in gridview
:
public class gridviewitem { public string description { get; set; } public imagesource image { get; set; } }
the next step parse xml file list of gridviewitem
s:
var xmlstring = await fileio.readtextasync(storagefile); var xml = xdocument.parse(xmlstring); var items = xml.element("rootnode").elements("itemnode").select(i => new gridviewitem { description = (string)i.element("descriptionnode"), image = parseimage(i.element("imagenode")) }).tolist();
i've assumed tags in xml rootnode
, itemnode
, descriptionnode
, imagenode
. don't know how image info stored in xml. logic convert imagesource
should in parseimage()
.
the thing left assign items
list above property in view model serving datacontext
, bind itemssource
:
<gridview itemssource="{binding items}" />
this basic idea. there's lot of details missing in reply that's best can based on question.
c# windows-store-apps
Comments
Post a Comment