c# - Data Will Not Bind WP -


im trying bind data xml file, ive followed tuts mdsn , other online sources keep getting error, if bind data listbox works fine.

  public void loadpage()     {         xdocument loadeddata = xdocument.load("page01.xml");          var data = query in loadeddata.descendants("page")                    select new pagereader                    {                        pagenumber = (int)query.element("pnumber"),                        chaptertitle = (string)query.element("ctitle"),                           chapternumber = (int)query.element("cnumber")                    };          layoutroot.datacontext = data;     } 

and xaml

  grid x:name="layoutroot" background="#fffffefe">     <stackpanel>         <grid>             <rectangle fill="#ff424242" horizontalalignment="left" height="60" stroke="black" verticalalignment="top" width="480"/>             <stackpanel orientation="horizontal">                 <textblock width="100"  textwrapping="wrap" maxwidth="100" maxheight="58" textalignment="center" horizontalalignment="center" verticalalignment="center" foreground="#ffb6aeae" fontfamily="{staticresource lob2}" text="{binding chapternumber}"/>                 <textblock width="280"  textwrapping="wrap" maxwidth="300" maxheight="58" textalignment="center" horizontalalignment="center" verticalalignment="center" foreground="#ffb6aeae" fontfamily="{staticresource lob2}" text="{binding chaptertitle}"/>                 <textblock width="100"  textwrapping="wrap" maxwidth="100" maxheight="58" textalignment="center" horizontalalignment="center" verticalalignment="center" foreground="#ffb6aeae" fontfamily="{staticresource lob2}" text="{binding pagenumber}"/>             </stackpanel>         </grid>         <grid height="30"></grid>         <textblock x:name="pagetext" height="640" scrollviewer.verticalscrollbarvisibility="visible"></textblock>     </stackpanel>     </grid> 

your data of type ienumerable<pagereader>, why work listbox listbox expecting collection.

if change

layoutroot.datacontext = data; 

to

layoutroot.datacontext = data.firstordefault(); 

at least should see data show on ui.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -