dotnet / dotnet/maui

Picker does not select an item when SelectedItem precedes ItemsSource in XAML attributes order

Open
#30,644 3 comments 1 reaction 0 assignees View on GitHub
area-controls-picker platform/android platform/ios platform/windows s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 14h
Merged PRs (30d)
296

Description

### Description

It appears that the XAML attribute order is important when binding the SelectedItem and ItemsSource.
If ItemsSource is first, followed by SelectedItem the picker will properly select the item.
If the order is reversed, the picker does not select the item.
My expectation is that the XAML attribute order should not matter and the picker should properly select the item in both scenarios.

### Steps to Reproduce

Run the reproduction project.
The main page contains two pickers:

- the first is "broken" - the SelectedItem attribute is specified first, followed by ItemsSource.
- the second is working properly - the ItemsSource attribute is specified first, followed by SelectedItem.

Change the order of the SelectedItem and ItemsSource attributes of the "broken" picker. Notice how it now selects the proper item.

### Link to public reproduction project repository

https://github.com/valentinba/PickerBindingsOrderBug

### Version with bug

9.0.90 SR9

### Is this a regression from previous behavior?

Not sure, did not test other versions

### Last version that worked well

_No response_

### Affected platforms

Android, Windows, iOS

### Affected platform versions

Android 21.0, Windows 10.0.17763.0, iOS 15

### Did you find any workaround?

Changing the attributes order seems to fix the issue.

### Relevant log output

```shell

```

Contributor guide

Open the contributing guide

Research direction

Start with the linked PickerBindingsOrderBug reproduction and compare the two Picker declarations, where SelectedItem and ItemsSource appear in opposite orders. Trace the corresponding Picker binding behavior in .NET MAUI; done means both declarations select the expected item on Android, Windows, and iOS.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop, frontend, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.