c# - Accessing images from isolated storage in XAML using "isostore:/" scheme -


i've downloaded images web , saved them isolated storage , want access images in xaml file, giving uri reference them.

i have verified isostorespy stored expect them , can create bitmapimages them if open file , read in byte stream. want optimize image handling passing uri model isolatedstorage location , letting xaml load image.

<image height="120" width="120" stretch="uniform" horizontalalignment="left">    <image.source>      <bitmapimage urisource="{binding podcastlogouri}" decodepixelheight="120" decodepixelwidth="120" />     </image.source> </image> 

this podcastlogouri uri value bound bitmapimage.urisource:

"isostore:/podcasticons/258393889fa6a0a0db7034c30a8d1c3322df55696137611554288265.jpg"

here's how i've constructed it:

public uri podcastlogouri {         {          uri uri = new uri(@"isostore:/" + podcastlogolocation);         return uri;     } } 

still, can't see image in ui. , sure image @ podcastlogolocation.

should possible reference images ui isolated storage in windows phone 8? doing wrong?

edit: if create bitmapimage directly using same path , use bitmapimage in xaml, works fine , can see image expect see there:

<image height="120" source="{binding podcastlogo}"  width="120" stretch="uniform" horizontalalignment="left"/> 
 public bitmapimage podcastlogo  {           {           stream stream = null;           bitmapimage logo = new bitmapimage();           using (var isostore = isolatedstoragefile.getuserstoreforapplication())           {               if (isostore.fileexists(podcastlogolocation))               {                  stream = isostore.openfile(podcastlogolocation, system.io.filemode.open, fileaccess.read);                  try                  {                       logo.setsource(stream);                  }                  catch (exception e)                  {                  }              }         }          return logo;      }  } 

i think i've done same thing you're trying do. i've found absolute location isolated storage stores file using isolatedstoragefile.getuserstoreforapplication(). "c:/data/users/defapps/appdata/<app product id>/local/<yourfile.png>";

i've tested workaround on windows phone 8 , works me...

1. xaml

<image width="40">     <image.source>         <bitmapimage decodepixelwidth="40" decodepixelheight="40" urisource="{binding path=icon}" />     </image.source> </image> 

2. viewmodel

private string _icon; public string icon {         {         return _icon;     }     set     {         if (value != _icon)         {             _icon = value;             notifypropertychanged("icon");         }     } } 

3. load data

filename = "myicon.png";  isolatedstoragefile store = isolatedstoragefile.getuserstoreforapplication(); if (!store.fileexists(filename)) {     using (isolatedstoragefilestream stream = new isolatedstoragefilestream(filename, filemode.create, fileaccess.write, store))         stream.write(imgbytes, 0, imgbytes.length); }  //get product id manifest. add using system.linq; if haven't guid productid = new guid((from manifest in system.xml.linq.xelement.load("wmappmanifest.xml").descendants("app") select manifest).singleordefault().attribute("productid").value); string storefile = "c:/data/users/defapps/appdata/" + productid.tostring("b") + "/local/" + filename;  this.items.add(new myviewmodel() { icon = storefile }); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -