c# - How to bind xml image in listbox in windows phone 8 -


how bind xml image in windows phone 8? have done methods not working, whenever debug application, contains source of image but, image not displaying.

code:

list<list> lst = new list<list>(); lst = (from query in doc.descendants("row") select new list    { id = convert.toint64(query.element("id").value),      icon = query.element("icon").value,      xyz = convert.toint64(query.element("xyz").value),      url = query.element("url").value, name = query.element("name").value }).tolist();     listbox1.datacontext = lst; 

xaml code:

            <listbox.itemtemplate>                 <datatemplate>                     <stackpanel orientation="horizontal">                                                <image source="{binding icon}" stretch="uniform" horizontalalignment="center" height="50" width="50" verticalalignment="top"/>                      </stackpanel>                 </datatemplate>             </listbox.itemtemplate>         </listbox> 

i think can try use converter (if search internet binding , converter, find many links, tutorials etc.). simple code can (i haven't tried it):

in xaml:

... xmlns:common="clr-namespace:yournamespace" ... <phone:phoneapplicationpage.resources>     <common:toimagesource x:key="converter"/> </phone:phoneapplicationpage.resources> ... <image source="{binding icon, converter={staticresource converter} }" stretch="uniform" horizontalalignment="center" height="50" width="50" verticalalignment="top"/> 

in .cs:

public class toimagesource : ivalueconverter {   public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)   {             if (value == null) return null;      else      {         byte[] imagebytes = convert.frombase64string(value);          using (memorystream stream = new memorystream(imagebytes, 0, imagebytes.length))         {           stream.write(imagebytes, 0, imagebytes.length);           bitmapimage bitmap = new bitmapimage();           bitmap.setsource(stream);           return bitmap;         }               }   }    public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture)   {   // implement convertback      } } 

you can read more binding , converters at msdn.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -