So I have this list of messages that define different sets of actions depending on their type, for this I use a datatemplate selector.
And this worked fine. But I soon noticed that the performance was disgustingly sluggish, scrolling was stupidly slow and loading in new items caused a slight hang of the app. Even though all the templates are very simple and basically consist of a Grid with nothing more than a title, subtitle, separator line and a bit of text.
So i set the listview's caching strategy to "RecycleElement" and at first this seemed to solve my issue. Scrolling was suddenly alot smoother, cells would load in alot faster and everything seemed great.
But then I started noticing that cells were giving me the wrong options or were attempting (and failing) to execute the wrong actions.
After a bit of breakpoint setting I noticed that when the page loads for the first time it creates a couple of cells from scratch (as you'd expect) and it uses my template selector correctly.
It's here that the problems start, If you then scrol a new cell into view xamarin blindly reuses the old cells instead of checking the type of the "newly scrolled" cell.
Even worse is that the order in which the cells were initially loaded gets reused on the new cells that are scrolled in view. For instance, if the initial load of the page created 3 cells:
cell1: type A
cell2: type B
cell3: type C
What happens then is that when you scroll cell 4 into view it will be displayed as a type A cell regardless of its actual type. cell 5 will be type B and cell 6 type C, and so on and so forth.
You get the point. And as you scroll up and down things seem to get even weirder, if i scroll up again cell1 might suddenly no long er be a type A.
I'm sure this is somewhat intended behavior but I was wondering if anyone else had come across this and found a way to either increase listview performance (drastically) without the caching strategy or a way to make it behave with a template selector?
Because right now it's not usable.