Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
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.
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.
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 188.8.131.52
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 184.108.40.206-pre3), but it will be available in an upcoming release. You'd do this by changing
appImage = new BitmapImage();
appImage = new BitmapImage();
appImage.ImageOpened += (sender, args) => ((IVisualElementController)Element)?.InvalidateMeasure(InvalidationTrigger.RendererReady);
(This is effectively what the default ImageRenderer for WinRT/UWP does internally.)
For older Forms versions, you could use a reflection hack to solve it: