Xamarin.forms: Picker value cleared when scrolling a CollectionView in iOS

Created on 21 Feb 2020  路  11Comments  路  Source: xamarin/Xamarin.Forms

Values selected in a picker are cleared when you scroll down a collection view and then back up. I found the same issue was logged for the ListView: https://github.com/xamarin/Xamarin.Forms/issues/4250. I altered the sample from issue 4250 to use a CollectionView and I can reproduce the issue.

Steps to Reproduce

  1. Run the sample
  2. Scroll down CollectionView items
  3. Now scroll the up the CollectionView items and you can see that the picker values cleared.

Expected Behavior
Picker values should not clear

Actual Behavior
Picker values cleared

Basic Information

  • Version with issue: Xamarin Forms 4.4.0.991640 and 4.5.0.282-pre4
  • IDE: Visual Studio Enterprise 2019 version 16.4.2 on Windows 10
  • Platform Target Frameworks:

    • iOS: 13.2

    • Android: not tested

    • UWP: not tested

  • Affected Devices: iPad Air

Reproduction Link
Picker_CollectionView_Issue.zip

collectionview bug

Most helpful comment

Why is this closed? The problem is still not fixed, my picker value gets cleared aswell when scrolling up or down...

All 11 comments

I'm using a bindable stacklayout to work around this issue since I don't have very many items in the list. Performance seems to be fine.

I'm using a bindable stacklayout to work around this issue since I don't have very many items in the list. Performance seems to be fine.

@jrpickett For smaller numbers of items, using a BindableLayout is an excellent choice. The BindableLayout will create instances of all your templated items, rather than using a pool of recycled items like CollectionView does. (See https://github.com/xamarin/Xamarin.Forms/issues/9200#issuecomment-643822589 for a more detailed explanation of what CollectionView is doing.)

If you find later that you need a larger number of items than BindableLayout can handle, you can add a property in your view model for the Picker's selection and bind the Picker to it.

Why is this closed? The problem is still not fixed, my picker value gets cleared aswell when scrolling up or down...

Has anyone found a workaround for this one? I just encountered it deep into a redesign and it's killing me.

Okay, the BindableLayout worked as an alternative. It's a shame that CollectionView has errors on all the platforms, I'm not sure it's usable for anything very complex at this point.

Okay, the BindableLayout worked as an alternative. It's a shame that CollectionView has errors on all the platforms, I'm not sure it's usable for anything very complex at this point.

It's true. BindableLayout works for this. Sorry that I didn't respond faster..

I don't understand why it's closed actually.
To use BindableLayout is a workaround and it doesn't work fine in all cases.
For example, there is pretty large collection of items in my app and I want tot use ColeectionView instead of BindableLayout because of virtualization and performance improvements. But I can't because of this very, very weird issue.

Any suggections?

Why is this closed? The problem is still not fixed, my picker value gets cleared aswell when scrolling up or down...

@cmpalmer66 @programmingworld1 @abondarenko

This was closed because it's not a bug. As I suggested upthread, you should take a look at the comments for issue 9200 for an explanation of why it's not a bug and how to use the CollectionView/CarouselView with data binding to achieve your goal.

I'm using binding and the thing is binded property is empty after a scrolling.

@abondarenko What does your DataTemplate and your Binding look like? Can you post your XAML/code?

Was this page helpful?
0 / 5 - 0 ratings