Skip to content

Prevent SelectedIndex/SelectedItem update loops in Picker - #39971

Merged
kubaflo merged 1 commit into
dotnet:candidate/11.0.1xx-sr2from
fmazzant:fix-8874-picker-selectedindex-loop
Nov 10, 2026
Merged

kubaflo merged 1 commit into
dotnet:candidate/11.0.1xx-sr2from
fmazzant:fix-8874-picker-selectedindex-loop

Conversation

@fmazzant

@fmazzant fmazzant commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem by only updating SelectedIndex if the value changes. Adds a unit test to ensure that changing ControlTemplate from SelectedIndexChanged does not cause recursive events (fixes #8874).

Description of Change

Issues Fixed

Fixes #8874

Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem by only updating SelectedIndex if the value changes. Adds a unit test to ensure that changing ControlTemplate from SelectedIndexChanged does not cause recursive events (fixes dotnet#8874).
@fmazzant
fmazzant temporarily deployed to copilot-pat-pool November 6, 2026 08:42 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39971

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39971"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Nov 6, 2026
@fmazzant
fmazzant temporarily deployed to copilot-pat-pool November 6, 2026 08:42 — with GitHub Actions Inactive
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@fmazzant! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @fmazzant! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@kubaflo

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Nov 6, 2026
@azure-pipelines

This comment has been minimized.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 0 findings

Reviewed commit c32cb30.

@MauiBot

MauiBot commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@fmazzant — existing-test verification for commit c32cb301.

Result PASSED Platform Android Commit c32cb301


🧪 Gate analysis — click to expand

✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence.

🧪 Unit tests
Test group Without fix With fix
PickerSelectedIndexChangedLoopTests ✅ Failed as expected (79s) ✅ Passed (50s)
Execution log excerpts

Without fix PickerSelectedIndexChangedLoopTests

     at Microsoft.Maui.Controls.Core.UnitTests.PickerSelectedIndexChangedLoopTests.<>c__DisplayClass3_0.<ChangingControlTemplateFromSelectedIndexChangedDoesNotLoop>b__0(Object s, EventArgs e) in /_/src/Controls/tests/Core.UnitTests/PickerSelectedIndexChangedLoopTests.cs:line 38
   at Microsoft.Maui.Controls.Picker.OnSelectedIndexChanged(Object bindable, Object oldValue, Object newValue) in /_/src/Controls/src/Core/Picker/Picker.cs:line 574
   at Microsoft.Maui.Controls.BindableObject.OnBindablePropertySet(BindableProperty property, Object original, Object value, Boolean didChange, Boolean willFirePropertyChanged) in /_/src/Controls/src/Core/BindableObject.cs:line 792
   at Microsoft.Maui.Controls.Element.OnBindablePropertySet(BindableProperty property, Object original, Object value, Boolean changed, Boolean willFirePropertyChanged) in /_/src/Controls/src/Core/Element/Element.cs:line 705
   at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) in /_/src/Controls/src/Core/BindableObject.cs:line 779
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) in /_/src/Controls/src/Core/BindableObject.cs:line 705
   at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value) in /_/src/Controls/src/Core/BindableObject.cs:line 601
   at Microsoft.Maui.Controls.Picker.set_SelectedIndex(Int32 value) in /_/src/Controls/src/Core/Picker/Picker.cs:line 173
   at Microsoft.Maui.Controls.Core.UnitTests.PickerSelectedIndexChangedLoopTests.ChangingControlTemplateFromSelectedIndexChangedDoesNotLoop(BindingMode mode) in /_/src/Controls/tests/Core.UnitTests/PickerSelectedIndexChangedLoopTests.cs:line 46
   at System.Reflection.MethodBaseInvoker.I

With fix PickerSelectedIndexChangedLoopTests

  Determining projects to restore...
  All projects are up-to-date for restore.
Test run for /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net11.0/Microsoft.Maui.Controls.Core.UnitTests.dll (.NETCoreApp,Version=v11.0)
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 11.0.0)
[xUnit.net 00:00:00.53]   Discovering: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:04.54]   Discovered:  Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:04.56]   Starting:    Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:04.70]   Finished:    Microsoft.Maui.Controls.Core.UnitTests
  Passed ChangingControlTemplateFromSelectedIndexChangedDoesNotLoop(mode: OneTime) [72 ms]
  Passed ChangingControlTemplateFromSelectedIndexChangedDoesNotLoop(mode: OneWay) [1 ms]
Test Run Successful.
Total tests: 2
     Passed: 2
 Total time: 5.6021 Seconds

PR head: c32cb301.

Without-fix baseline: e6abee71.

@MauiBot MauiBot added s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) and removed s/agent-review-in-progress AI review is currently running for this PR labels Nov 6, 2026

@kubaflo kubaflo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The picker tests failed

@fmazzant fmazzant left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking, @kubaflo! I looked into it and I don't think the failures come from this change.

The Picker failures are only in the MacCatalyst UI tests, and almost every category fails there, not just Picker. The logs show the app window ends up partly off-screen on the agent (window pixels (-384,60,...) are outside screenshot bounds), so screenshots don't match and some taps miss. That's why Picker_SetSelectedIndex_VerifySelectedIndexAndItem reads -1. main fails the same way, including that test (e.g. build 1667202). It seems to have started around Nov 4, maybe after #39876, but I haven't checked that on a Mac.

On the unit test side, all Picker tests pass. The only failure is ToolbarTests.RemoveRootPageHidesBackButton on the Windows Debug job, which passes everywhere else and locally, so it looks flaky.

Could you re-run the failed checks when you get a chance? Thanks!

@kubaflo
kubaflo changed the base branch from main to candidate/11.0.1xx-sr2 November 10, 2026 20:59
@kubaflo
kubaflo merged commit 8fe018c into dotnet:candidate/11.0.1xx-sr2 Nov 10, 2026
148 of 185 checks passed
kubaflo pushed a commit that referenced this pull request Nov 11, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes #8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Nov 13, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes #8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Nov 16, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes #8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Nov 16, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes #8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Nov 17, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes #8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Nov 18, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes #8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Nov 18, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes #8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Nov 18, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes #8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Nov 19, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes #8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Nov 22, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes #8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Nov 23, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes #8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
@kubaflo kubaflo added this to the .NET 11 SR2 milestone Nov 24, 2026
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Nov 26, 2026
Fixes an infinite loop when synchronizing SelectedIndex and SelectedItem
by only updating SelectedIndex if the value changes. Adds a unit test to
ensure that changing ControlTemplate from SelectedIndexChanged does not
cause recursive events (fixes dotnet#8874).

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes dotnet#8874

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
@fmazzant
fmazzant deleted the fix-8874-picker-selectedindex-loop branch December 2, 2026 15:12

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — c32cb301 Deployed Nov 6, 2026 by fmazzant via conclusion #2742
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-picker Picker community ✨ Community Contribution s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Picker's SelectedIndexChanged event run infinitely when changing ControlTemplate

3 participants