Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Set ListView's ItemsSource within Task.Run, causes ViewCell not populated

$
0
0

I'm having constant problem whenever I try to load ListView's ItemsSource in background thread, i.e. using Task.Run();
In the subclass of ListView:

    ItemTemplate = new DataTemplate (typeof(ProductItemCell));
    Task.Run (() => {// Comment this line and the last line, ListView's ViewCell "ProductItemCell" gets populated without any problem. Uncomment leads                   
                              // to the unpopulated ViewCell  

                // Here do a join query to get data from database   
                    List<Product> prods = (List<Product>)ProductTable.Instance.GetItems(cateId);
                    List<ProductImages> prodImgs = (List<ProductImages>)ProductImagesTable.Instance.GetProductImagesOneForEachSku(prods);
                    ItemsSource = prods.Join(
                        prodImgs,
                        prod => prod.Sku,
                        prodImg => prodImg.Sku,
                        (prod, prodImg) => 
                        new ProductImageProductJoinMemory(prod, prodImg)
                    );
                    ItemTemplate.CreateContent ();
    //});

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>