Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy are BitmapImages failing to load and display properly in my GridView?
    primarykey
    data
    text
    <p>I have a GridView with elements containing a TextBlock and an Image. The TextBlock always populates fine, but the Image, once in a while, does not get loaded for one or two items. If I refresh the data source, the image correctly displays. I think the issue is with the timing (all data fetching is done asynchronously). Here is the code that fetches the images from disk. All images are 140x140 pixels and are PNG files.</p> <pre><code>public async Task&lt;List&lt;BitmapImage&gt;&gt; getPhotos() { photos.Clear(); //clears list of photos IReadOnlyList&lt;IStorageFile&gt; files = (IReadOnlyList&lt;IStorageFile&gt;)await folderHierarchy.Last().GetFilesAsync(); //reads in all files from current working directory foreach (StorageFile currentFile in files) //for each file in that directory { if (currentFile.Name.EndsWith(".png")) //only handle png files { photos.Add(await getBitmapImageAsync(currentFile)); //actually read in image from separate async method (bellow) } } return photos; } public async Task&lt;BitmapImage&gt; getBitmapImageAsync(StorageFile storageFile) { BitmapImage image = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream) await storageFile.OpenAsync(FileAccessMode.Read); image.SetSource(stream); return image; } </code></pre> <p>I run this method using: List tilePicturesArray = await dataFetcherClass.getPhotos(); The original photos List does not contain all of the photos. Something wrong is happening in that first block of code (above). The next step is when I populate the Image and TextBox via in my List (GridViewCell is a class that I made to bind data in my GridView) The list of GridViewCell objects is what is binded to my GridView. I don't believe that this is the issue.</p> <pre><code>for (int x = 0; x &lt; tileTitlesArray.Count; x++) //this IS running inside of an async method { GridViewCell singleCell = new GridViewCell(); singleCell.tileName = tileTitlesArray.ElementAt(x); singleCell.tileImage = tilePicturesArray.ElementAt(x); tileCells.Add(singleCell); //tileCells is the datasource for gridview } </code></pre> <p>What do you think would be causing the issue? I added a little refresh button which basically reruns the above loop (to repopulate the gridview datasource and tiles) but does not refetch the tilePicturesArray, so the binding is done using the same original List of BitmapImages (and the same tiles are still missing pictures)</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.
 

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