Bug 43832 - Using a ListView with a DataTemplateSelector and RecycleElement results in wrong behavior on cells
Summary: Using a ListView with a DataTemplateSelector and RecycleElement results in wr...
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Chris King
Depends on:
Reported: 2016-08-29 15:06 UTC by John Hardman
Modified: 2017-06-19 18:50 UTC (History)
6 users (show)

Tags: ListView RecycleElement DataTemplateSelector DataTemplate
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description John Hardman 2016-08-29 15:06:23 UTC
When using a ListView with a DataTemplateSelector and RecycleElement as the caching strategy, with two different DataTemplates being used, the ViewCells sometimes become unresponsive. The ListView can be scrolled, but taps on the ViewCells are ignored.

I have only seen this happen on two devices, one Android and one iOS. I have never seen it on any other devices (UWP, WinRT, Android or iOS). Even on the Android device where it occurs, it does not occur every time.

If I change RecycleElement to RetainElement, the problem does not occur.
If I only have one DataTemplate in use, even with RecycleElement, the problem does not occur.
The problem occurs when RecycleElement is used in conjunction with a DataTemplateSelector and more than one DataTemplate type. It seems to be timing related, so I suspect an issue around async/Tasks in the DataTemplateSelector handling within ListView.

It seems to be what others have talked about here:

And which I raised (before I saw that thread) here:
Comment 1 John Hardman 2016-08-29 23:00:07 UTC
As mentioned previously, the problem does not show up every time even on the devices where it does happen.

My suspicion (other than it being timing related, around async/Tasks in the DataTemplateSelector/RecycleElement handling within ListView) is as follows:

The problem shows up when I have more than one DataTemplate used within the ListView.
The first DataTemplate I use sets IsEnabled=false on the ViewCell.
The other DataTemplates set IsEnabled=true on ViewCells.
I think that the RecycleElement handling is not resetting IsEnabled correctly when switching from one DataTemplate to another.
Comment 2 Chris King 2016-10-06 19:27:55 UTC
Our test Xamarin.Forms.Controls\GalleryPages\ListViewDemoPage.cs uses RecycleElement and multiple DataTemplates so should be able to repo. However, after playing around with my device Nexus 5 and emulators I was unable to reproduce. Don't doubt it's happening but will need more investigation.

John, would you be willing to attach a small reproduction just so we're sure we're using an app that someone has observed the issue while using? Also, could you tell us which devices you see the issue on? We have a test cloud so there's a good chance we have the devices. 

Warm regards,
Comment 3 Samantha Houts [MSFT] 2017-06-19 18:50:08 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!