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

Problem with ItemAppearing event in ListView

$
0
0

I'm trying to do dynamic data load in ListView when scrolling to the end. For this, I use the event ItemAppearing.

The problem is that when I first add data ItemSource, the event ItemAppearing is triggered for each Item, even for those which do not need to be seen on the screen (so the event is triggered, and the last element that creates a problem). However, after the download of the data and then scroll through the event ItemAppearing works correctly, ie once, only when displaying the new Item.

Maybe this is somehow related to the fact that IsGroupingEnabled = true?

ListView:

var listView = new ListView
            {
                HasUnevenRows = true,
                ItemTemplate = new DataTemplate(typeof(CategoryProductsCell)),
                ItemsSource = productGroups,
                IsGroupingEnabled = true,
                GroupDisplayBinding = new Binding("Name"),
            };

ItemAppearing:

listView.ItemAppearing += (sender, e) => {
                if (isLoading || productGroups.Count == 0) return;
                if (e.Item is CategoryProduct)
                {
                    if ((e.Item as CategoryProduct).ID == productGroups.Last().Last().ID)
                    {
                       // AddProductsSubgroup(tempCategories);
                    }
                }
            };

ItemSource Item:

public class ProductsInCategory : List<CategoryProduct>
    {
        public String Name { get; private set; }        
        public ProductsInCategory(String Name,List<CategoryProduct> productList)
        {
            this.Name = Name;
            this.AddRange(productList);
        }
    }

Viewing all articles
Browse latest Browse all 77050

Trending Articles



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