Bug 41087 - Image loading issue with UWP
Summary: Image loading issue with UWP
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.2.0
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-05-14 04:18 UTC by Cody Beyer (MSFT)
Modified: 2016-07-04 15:11 UTC (History)
5 users (show)

Tags: Windows ac
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Cody Beyer (MSFT) 2016-05-14 04:18:14 UTC
Summary : When loading an image in a listview with a custom renderer (ImageRenderer), if AWAIT statement is used to get the image before setting it in the control, all the images won't show up once the page loads. We have to rotate the device (landscape mode) and then all the images will shows up. 

Overview: This issue specifically occurs with the await statement. Not all images are rendered on the first load. However if we rotate the device, all images are rendered properly. Also If await statement is not used, rendering of images works just fine. 

Steps : Run the Sample application (attached) on windows emulator. 

https://dl.dropboxusercontent.com/u/9600536/ImageWinSample.zip 


Actual Results : Not All images are loaded on the first load (Portrait mode). You might observe the first images is not loaded. Sometimes as many as half of the images are not loaded. 

Expected Results: All images should be loaded on the first load itself.
Comment 1 John Hardman 2016-05-20 11:04:46 UTC
I wonder if this is related to the problem I am seeing on UWP and WinRT 8.1, described in the thread at https://forums.xamarin.com/discussion/65313/no-images-in-a-grid-inside-a-listview-on-windows-phone

I am using 2.2.0.31
Comment 2 E.Z. Hart [MSFT] 2016-06-08 16:12:18 UTC
This isn't exactly an issue with 'await'; it's actually a race condition with the platform's internal asynchronous image loading. The Windows Image control and the underlying BitmapImage classes already load images asynchronously by default. In the right circumstances, you could probably see some of your images failing to appear even if your 'UpdateImage()' method weren't marked as 'async'.

The fix for your custom renderer example would be to handle the 'ImageLoaded' event of your Image control and signal that the renderer is ready for layout. Unfortunately, you can't do this right now because the method you need is still marked internal (as of 2.3.0.46-pre3), but it will be available in an upcoming release. You'd do this by changing 

       appImage = new BitmapImage();

to

    appImage = new BitmapImage();
    appImage.ImageOpened += (sender, args) => ((IVisualElementController)Element)?.InvalidateMeasure(InvalidationTrigger.RendererReady);
    
(This is effectively what the default ImageRenderer for WinRT/UWP does internally.)