2

So I set out to do a simple interface with a search field, a couple of "tabs" that represent data categories and a CollectionView to show the data as the figure below

enter image description here

During development I noticed that when I set a tab that had more data, the loading would take a longer time (too long), and everything would kind of get stuck waiting for it to respond, so I started making some tests on how the CollectionView gets populated (via the ChildAdded event) and here are my findings

In most cases the CollectionView will load Childs that fit in the view (in my screenshot for example it would only load 4 children), and everytime you scroll it will load the appropriate number of items to fill the screen. This happened when the collection only had this types of ancestor Elements - ContentPage, Frame, RefreshView. ScrollView, TableView, Grid (if not set to Auto), HorizontalStackLayout, FlexLayout, toolkit:DockLayout

However there are other cases where all the childs are loaded right away, this happens when the CollectionView is the descendant of this types - ScrollView, VerticalStackLayout, StackLayout, AbsoluteLayout, Grid (when set to auto)

Does anyone have any idea why this happens?

Also is it possible to make it load a fixed number of Children each time, let's say instead of loading enough items to fill the View I want to load 10 items (note that loading the data incrementally with RemainingItemsThresholdReachedCommand for example, only loads the data into memory, and doesn't create a child item in the View)

Note this tests are not exhaustive and there can be other combinations of ancestors/configurations that have different results, and they where only done with Android emulator

Safin Ahmed
  • 560
  • 4
  • 12
  • 3
    **1)** *"Does anyone have any idea why this happens?"* In complex layouts, LayoutManager probably becomes uncertain how many items are visible; set a `HeightRequest` on `CollectionView`, to give it a hint. **2)** *"load a fixed number of Children each time"* See https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/collectionview/populate-data?view=net-maui-7.0#load-data-incrementally for options. – ToolmakerSteve Jan 20 '23 at 21:09
  • Yes, I have pretty good idea why this happens. And all the examples of loading all items at once, should be avoided at all cost. Also, remaining items are used for situations "oh no, I am reaching the end of the list, I should do something". You literally tested how to use CollectionView the wrong way. The results are expected. – H.A.H. Jan 23 '23 at 10:52
  • 1
    I tested how to use CollectionView in different parents, it included the wrong way and also the right way. You mention you have a pretty good idea why it happens, but don't explain it – Safin Ahmed Jan 23 '23 at 13:48
  • You can try to make the collectionview show the number of items you want by set the ItemSource when you render it. – Liyun Zhang - MSFT Jan 24 '23 at 09:16

0 Answers0