listviewitem - Load Images In a ListView stored in local App folder windows 8 app -
i have button on click of have populate multiple images in listview. have seen stackoverflow posts same did not help. want populate images app local folder, , set source of listview. sample of how select multiple image files folder , adding listview. e.g.
var uri = new windows.foundation.uri('ms-appx:///images/logo.png');
var file = windows.storage.storagefile.getfilefromapplicationuriasync(uri);`
this select 1 image stored in app folder, how loop through multiple images , add in listview.
also in addition have grid added. when select image listview should load in grid. on select event changed how should grab file path of image or load selected image in grid.
thanks in advance.
you need reference proper storagefolder , can loop through storagefiles. can create object storagefile. since doesn't sound you're using mvvm, i'll show quick code behind example.
//helper class store uri of image , file name public class myimage { public myimage(storagefile file) { this.uri = new uri(string.format("ms-appx:///images/{0}", file.name); this.name = file.name; } public uri uri { get; set; } public string name { get; set; } } //called button click event private async task loadimagesasync() { //this get's installation root folder, traverse images folder //in uri, equivalent "ms-appx:///images" var imagesfolder = await windows.applicationmodel.package.current.installedlocation.getfolderasync("images"); var files = await imagesfolder.getfilesasync(); //may want filter image types here var itemssource = files.select(x => new myimage(x)); //assume listview has x:name attribute of "mylist" this.mylist.itemssource = itemssource; } //called selectionchanged event listview private void setimage() { var myimage = this.mylist.selecteditem myimage; //assume have image in xaml x:name of "gridimage" this.gridimage.source = new bitmapimage(myimage.uri); }
Comments
Post a Comment