Tuesday, 27 August 2013

Populate DefaultViewModel["Items"] with Images Windows Metro

Populate DefaultViewModel["Items"] with Images Windows Metro

I'm trying to load a folder of images into my Windows Metro app by
populating a list of objects that encapsulate a Title and Image field and
then assigning this to DefaultViewModel["Items"]. The wrapper class I have
for this information is the following:
public class SlideData
{
// slide collection that will be used to populate app slides page
public List<Slide> Slides = new List<Slide>();
public SlideData(IReadOnlyList<StorageFile> files)
{
int counter = 1;
foreach (StorageFile file in files)
{
Slides.Add(new Slide(counter.ToString(), file.Name));
}
}
public class Slide
{
public Slide(String title, String Image)
{
this.Title = title;
this.Image = Image;
}
private String Title { set; get; }
private String Image { set; get; }
}
}
Then the method in the page I want to assign elements to my GridView to
has this in the LoadState method to load and assign these slides:
protected async override void LoadState(Object navigationParameter,
Dictionary<String, Object> pageState)
{
var folderPicker = new FolderPicker();
folderPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
folderPicker.FileTypeFilter.Add(".png");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
if (folder != null)
{
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
SlideData slides = new SlideData(files);
this.DefaultViewModel["Items"] = slides.Slides;
}
}
The good news is in my GridView, I'm getting all of the slides I want to
show up, but they're blank, having no title or image associated with them;
essentially, I just want to load all of the PNGs in a given folder, assign
them the title of 1-N, then display them here in this view before allowing
the user to click on any given one and view it fully. Help is greatly
appreciated!

No comments:

Post a Comment