[Bug] Xamarin.Forms Picker - One Picker selection clears all the options of the other picker in the same page

Paul 296 Reputation points
2020-11-24T10:13:50.94+00:00

https://github.com/xamarin/Xamarin.Forms/issues/12956

Hi! I'm working on an app built using Xamarin.Forms. I just upgraded from Xamarin.Forms 3.4.0.1029999 to 5.0.0.1709-pre4. After this upgrade, I'm facing a new issue wherein a page that has multiple pickers, selecting an option in one picker immediately clears all the options of the other picker in the same page.
I also tried downgrading to latest stable version of Xamarin.Forms i.e., 4.8.0.1687

Steps to Reproduce
Tap a picker, select an option and click done.
Instantly, the other picker doesn't show any selected item.
Click this other picker, you will see the options of this other picker are totally empty!

Expected Behavior
Should not affect/clear the other picker's options or set it to null

Actual Behavior
The other picker options are fully empty!

Basic Information
Version with issue: 5.0.0.1709-pre4 & 4.8.0.1687
Last known good version: 3.4.0.1029999
Platform Target Frameworks: iOS

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,296 questions
{count} votes

Accepted answer
  1. Paul 296 Reputation points
    2020-11-25T14:15:22.687+00:00

    Thank you JESUS for His help. So, the problem is identified.

    In my code, changing the Picker selected value modifies the other picker. But,

    OnItemsSourceChanged is now getting called only when a binded model of list type property (PickerOptionsList ) is changed as follows :
    (1) PickerOptionsList = null;
    (2) PickerOptionsList = new List<OptionsModel>();

    And due to some changes/commits in one of the latest version (after 3.4.0.1029999), OnItemsSourceChanged is not getting called when elements are added to the the ItemSource List type model property(E.g. PickerOptionsList ) using Add() method. For e.g.

    PickerOptionsList.Add(...);
    

    For now, as a workaround I'm adding those values like the example below in some areas of code:

    PickerOptionsList = new List<OptionsModel>() {
    new Option(){ Id = 1, Name="A"},
    new Option(){ Id = 2, Name="B"},
    new Option(){ Id = 3, Name="C"},
    new Option(){ Id = 4, Name="D"}
    };
    

    I'm working in the code areas/scenarios where the element is added based on a condition..

    There is no problem on initial binding of the List (PickerOptionsList). But it happens when it is later changed (added) with elements (more options)..

    NOTE : In my code, during initial binding and on the change that happens later, the PickerOptionsList (ItemSource) is set to null, instantiated and then elements are added using Add()

    0 comments No comments

0 additional answers

Sort by: Most helpful