Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Cannot correctly set selectedIndex of picker when the list contains duplicate items[Bug] #15102

Open
Enigma86d opened this issue Jan 28, 2022 · 0 comments
Labels
a/picker s/unverified New report that has yet to be verified t/bug 🐛

Comments

@Enigma86d
Copy link

Enigma86d commented Jan 28, 2022

Description

I create a Xamarin Forms project for Android and I write a picker in xaml.
In the xaml file I also write a few items in the ItemsSource, making sure that there are at least two duplicate items.
In the c file I try to set the selectedIndex to the index of the second duplicate item.
The index will be wrongly set to the first duplicate item (not the second one).
Microsoft documentation does not say that picker has to have unique items
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/picker/

Steps to Reproduce

  1. Create Xamarin project for mobile phones
  2. Set Android as the starting project
  3. In xaml write a picker that has at least tow duplicate items
  4. in c file try to set the selectedIndex to the second duplicate item
    <StackLayout>
        <Picker x:Name="picker"
        Title="Select a monkey"
        TitleColor="Red">
            <Picker.ItemsSource>
                <x:Array Type="{x:Type x:String}">
                    <x:String>Baboon</x:String>
                    <x:String>Capuchin Monkey</x:String>
                    <x:String>Blue Monkey</x:String>
                    <x:String>Squirrel Monkey</x:String>
                    <x:String>Golden Lion Tamarin</x:String>
                    <x:String>Howler Monkey</x:String>
                    <x:String>Capuchin Monkey</x:String>
                    <x:String>Japanese Macaque</x:String>
                </x:Array>
            </Picker.ItemsSource>
        </Picker>
    </StackLayout>
        protected override void OnAppearing()
        {
            base.OnAppearing();
            picker.SelectedIndex = 6;
            int a = picker.SelectedIndex; //a will be equal with 1 instead of 6
        }

Expected Behavior

the selectedIndex to be set to the correct item

Actual Behavior

the selectedIndex is set to the first duplicate item, not the requested item

Basic Information

  • Version with issue:
  • Last known good version:
  • Platform Target Frameworks:
    • Android: 11.0 (R)
  • Android Support Library / AndroidX Version:
  • NuGet Packages: Xamarin Forms 5.0.0.2337 and Xamarin Essentials 1.7.1 (latest at this time)
  • Affected Devices: Android

Environment

Show/Hide Visual Studio info
Microsoft Visual Studio Community 2019
Version 16.11.7
VisualStudio.16.Release/16.11.7+31911.196
Microsoft .NET Framework
Version 4.8.03752

Installed Version: Community

Visual C++ 2019   00435-60000-00000-AA776
Microsoft Visual C++ 2019

ASP.NET and Web Tools 2019   16.11.94.52318
ASP.NET and Web Tools 2019

Azure App Service Tools v3.0.0   16.11.94.52318
Azure App Service Tools v3.0.0

C# Tools   3.11.0-4.21403.6+ae1fff344d46976624e68ae17164e0607ab68b10
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Graphical Debugging Extension   1.0
Graphical Debugging Visual Studio Extension allows to view graphical representation of variables, e.g. Boost.Geometry models or vectors of values.

HotReload Extension   1.4.0
Xamarin.Forms HotReload Visual Studio Extension

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   16.10.15 (552afdf)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.11.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools   16.0.30526.2002
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.11.0-4.21403.6+ae1fff344d46976624e68ae17164e0607ab68b10
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   16.11.0-beta.21514.6+b6c2c4f53ea3a08fa603ea93d6d2f808a62a21d1
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.11.000.197 (d16-11@6934992)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.11.0.47 (remotes/origin/d16-11@e0d612363)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.10.5 (355b57a)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   12.0.0.3 (d16-11/f0e3c2d)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: c633fe9
    Java.Interop: xamarin/java.interop/d16-11@476bb5b
    ProGuard: Guardsquare/proguard/v7.0.1@912d149
    SQLite: xamarin/sqlite/3.35.4@85460d3
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-11@87af37b


Xamarin.iOS and Xamarin.Mac SDK   15.2.0.17 (738fde344)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Build Logs

Screenshots

Reproduction Link

Workaround

@Enigma86d Enigma86d added s/unverified New report that has yet to be verified t/bug 🐛 labels Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/picker s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

No branches or pull requests

2 participants