dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.82k stars 1.66k forks source link

Picker regression in 8.0.60 #23367

Open BurningLights opened 2 days ago

BurningLights commented 2 days ago

Description

There is a regression in the behavior of Picker when, upon selection of an item, a new item is inserted into an ObservableCollection that serves as the ItemsSource before the currently selected item, and the SelectedIndex is incremented to keep the same item selected. This worked in 8.0.40 and before, and now in 8.0.60 and 8.0.61 results in an infinite loop that locks up the application.

Steps to Reproduce

  1. Create a new MAUI Project
  2. In the MainPage, create an ObservableCollection property to serve as the ItemsSource and an int property to serve as the SelectedIndex
  3. In the setter for the SelectedIndex property, if the new value is equal to 0, insert a new item at the beginning of the ObservableCollection and then increment the SelectedIndex property.
  4. Ensure that the ObservableCollection is populated with a couple options and the SelectedIndex is set to the second item in the list.
  5. Set the MainPage's BindingContext to itself.
  6. Add a Picker to the XAML and bind the ObservableCollection property to ItemsSource and the integer property to SelectedIndex.
  7. Run the application
  8. Select the first option from the picker.
  9. The application will lock up on version 8.0.60 or later. It should insert a new item at the beginning and keep the current selection.

Link to public reproduction project repository

https://github.com/BurningLights/MauiPickerIssue

Version with bug

8.0.60 SR6

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.40 SR5

Affected platforms

Android, Windows

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

github-actions[bot] commented 2 days ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.