Lazy Loading / Virtualization advise. #18040
Replies: 2 comments 4 replies
-
Ok i think now i am going a bit crazy :-) Just tried the exact same code on Desktop ( Linux ) and in the Browser (WASM) The above code does the right thing in the browser, but preloads everything on the desktop....... |
Beta Was this translation helpful? Give feedback.
-
This can be done. But you need to restructure your view model a bit and then bind to a task. I asked a similar question a long time ago so I will just link it and the discussion: To be clear though, Avalonia's virtualisation only virtualises view items. Meaning it wont try to render anything that's not needed. View model virtualisation is your responsibility to handle. |
Beta Was this translation helpful? Give feedback.
-
Hi !
We have quite a few datasets that are loaded via our REST API, and that make no sense ( or take to long ) to download completely. For this reason we would like to implement lazy loading ( as we would do in our web frontend )
I simplified our scenario:
Page has Limit Items and obviously the total count of results.
Now to achieve that i implemented a custom wrapper collection that implements INotifyCollectionChanged and IList that bascially for each indexing e.g calling this[index] gives back a default MyItem and queues the backend load, while also debouncing etc... and when the results are there fires the approprivate collection changed events. This works quite well in isolation.
Now when i bind this to a list box, it works , but enumerates all the items in my virtual list ( so that i have to load all pages of the backend ) even though the api returns 1000s of items and the listbox can only display maybe 10 in the space it is allowed.
Obviously i replaced the items panel of the list box with a VirtualizingStackPanel
I was under the impression this would only try to render the actually potentially visible items and not go through all of them and the render the subset needed......
Is this scenario supported at all ? What would be other options in Avalonia for this ? ( forgoing explicit pagination of course with some pagination ui )
My frontend deifnition looks like this:
Beta Was this translation helpful? Give feedback.
All reactions