Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to use the async APIs to access files in ApplicationData in WinJS, such as the getFileAsync function used below (this is a helper function I use in databinding for one of my apps):</p> <pre><code>function getLocalLargeMapTile(item) { return new WinJS.Promise( function (completed, error, progress) { var filename; var sourceFolder; if (item.latlong) { var latandlong = item.latlong.split(", "); var lat = latandlong[0]; var lon = latandlong[1]; filename = lat + lon + ".png"; var appData = Windows.Storage.ApplicationData.current; sourceFolder = appData.localFolder; sourceFolder.getFileAsync(filename).then(function (file) { var mapUrl = window.URL.createObjectURL(file, { oneTimeOnly: true }); completed(mapUrl); }, function (error) { handleError(error) }); } else { filename = "ms-appx:///images/megaphone_256x256.png"; completed(filename); } } ); } </code></pre> <p>What I'm doing in the helper function is checking whether my data includes a latitude and longitude, and if so, checking for a file with a matching filename, and since those files are in the Application Data folder, wrapping the file with an objectURL and returning a promise with the objectURL. Otherwise, I simply return an ms-appx url pointing to a static file in the app's images folder. Here's how I call this helper function, from a programmatic template (I don't think you can do this with a declarative template):</p> <pre><code>var image = document.createElement("img"); image.className = "item-image"; image.src = "ms-appx:///images/megaphone_256x256.png"; result.appendChild(image); // additional code omitted var promise = mapTileUtil.getLocalMapTile(currentItem); promise.done(function (mapTileUrl) { image.src = mapTileUrl; }); </code></pre> <p>For more info on templating functions, which provide greater control over the rendered markup than declarative templates, check out:</p> <p><a href="http://msdn.microsoft.com/en-us/library/windows/apps/jj585523.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/apps/jj585523.aspx</a></p> <p>and</p> <p><a href="http://go.microsoft.com/fwlink/p/?linkid=231499" rel="nofollow">http://go.microsoft.com/fwlink/p/?linkid=231499</a></p> <p>For more information on Windows Store app development in general, register for <a href="http://bit.ly/gd30tolaunch" rel="nofollow">App Builder</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload