DataTemplateSelector bug with Android phones

CatNaisCatNais Member ✭✭

Hello !!

I created a listview with a data template selector based on this model : :

 public class PersonDataTemplateSelector : DataTemplateSelector
        public DataTemplate ValidTemplate { get; set; }

        public DataTemplate InvalidTemplate { get; set; }

        protected override DataTemplate OnSelectTemplate (object item, BindableObject container)
            return ((Person)item).DateOfBirth.Year >= 1980 ? ValidTemplate : InvalidTemplate;

For iOS, all is working fine but for Android, the method "OnSelectTemplate (object item, BindableObject container)" is called multiple times for only one line. So, if you have several lines, this method is called an infinite numbers of times.

To reproduce this, install whatever project with a listview with a data template selector and put a breakpoint in the OnSelectTemplate.

I tested with others projects :

    => same bug

I am wondering why? And for me, these infinite calls slow down my app.
I tested with two differents mobiles : Samsung and Sony.

I am on Visual Studio Community for Mac.

Thank you for your help !

Sign In or Register to comment.