Skip to content

fix: RadioMenuFlyoutItem deselect when initial IsChecked set in XAML - #23240

Merged
MartinZikmund merged 5 commits into
masterfrom
dev/mazi/issue19090
May 14, 2026
Merged

MartinZikmund merged 5 commits into
masterfrom
dev/mazi/issue19090

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #19090

PR Type:

🐞 Bugfix

What changed? 🚀

The bug

When a RadioMenuFlyoutItem had IsChecked="True" set in XAML before GroupName in the attribute order (as in the repro from #19090), clicking another item in the same group did not uncheck the originally-checked item — the group selection was effectively impossible to change.

<RadioMenuFlyoutItem Text="Medium" IsChecked="True" GroupName="SizeGroup" />

Root cause

RadioMenuFlyoutItem keeps a thread-static s_selectionMap keyed by group name. When XAML applied IsChecked="True" first, GroupName was still its default empty string, so the item registered itself in the map under "". By the time the user clicked a sibling, lookups by the real group name found nothing and skipped the unchecking step.

The Uno port was synced from a WinUI 2.6-era commit and was missing the OnLoaded handler that WinUI added later precisely for this scenario. WinUI's OnLoaded re-runs UpdateCheckedItemInGroup() once all XAML-applied properties (including GroupName) are guaranteed to be set, fixing the registration.

The fix

  • Port the WinUI 3 OnLoaded handler that re-registers the checked item under its real GroupName.
  • Replace the C# finalizer with a deterministic OnUnloaded handler matching WinUI's OnUnloaded (the finalizer was unsafe — C# finalizers run on the GC thread and can't reliably touch UI state).
  • Add Given_RadioMenuFlyoutItem.When_IsChecked_Set_Before_GroupName_In_Xaml runtime test that mirrors the issue's exact XAML. Verified to fail before the fix and pass after.

Bonus: WinUI 3 style sync

Folded in alongside the fix while in the area:

  • RadioMenuFlyoutItem_themeresources.xaml: replaced with verbatim 1:1 copy of WinUI 3 (commit 69097129a8). Drops the four legacy _rsX_themeresources_v1.xaml Win10 OS-contract fallbacks that were superseded at merge time.
  • MenuFlyout_themeresources.xaml: replaced the five legacy WinUI 2.x revisions (19h1, rs1, rs2, rs4, rs5) with a verbatim 1:1 copy of WinUI 3 (commit 9d6fb15c08). Brings MenuFlyoutPresenter / MenuFlyoutItem / MenuFlyoutSubItem / ToggleMenuFlyoutItem / SplitMenuFlyoutItem styles in line with current WinUI.

Two minor Uno-specific extras from the legacy MenuFlyout files are intentionally dropped: the not_win:Glyph="&#xE73E;" SubItemChevron override (was in rs5) and the LanguageSwitcherMenuFlyoutItemPlaceholderThemeThickness resource (was in 19h1).

PR Checklist ✅

Copilot AI review requested due to automatic review settings May 11, 2026 11:48

Copilot AI 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.

Pull request overview

This PR fixes RadioMenuFlyoutItem group deselection when IsChecked="True" is applied from XAML before GroupName (issue #19090) by re-registering the checked item once it’s loaded, and adds a runtime test that reproduces the attribute-order scenario. It also syncs RadioMenuFlyoutItem / MenuFlyout theme resources to WinUI 3 equivalents and removes legacy per-contract XAML resource revisions.

Changes:

  • Add Loaded/Unloaded handlers to RadioMenuFlyoutItem to re-register checked items after XAML property application and to deterministically clean up group tracking.
  • Replace legacy RadioMenuFlyoutItem and MenuFlyout theme resource XAML revisions with WinUI 3-aligned theme resources.
  • Add a runtime test reproducing the XAML attribute-order bug (IsChecked before GroupName).

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Uno.UI/UI/Xaml/Controls/RadioMenuFlyoutItem/RadioMenuFlyoutItem.Properties.cs Updates WinUI/MUX reference commit metadata.
src/Uno.UI/UI/Xaml/Controls/RadioMenuFlyoutItem/RadioMenuFlyoutItem.cs Adds Loaded/Unloaded handling and changes group-selection map storage to fix XAML attribute order behavior.
src/Uno.UI/UI/Xaml/Controls/RadioMenuFlyoutItem/RadioMenuFlyoutItem_themeresources.xaml Replaces theme resources with WinUI 3-aligned styles/templates.
src/Uno.UI/UI/Xaml/Controls/RadioMenuFlyoutItem/RadioMenuFlyoutItem_rs1_themeresources_v1.xaml Removes legacy theme resource revision.
src/Uno.UI/UI/Xaml/Controls/RadioMenuFlyoutItem/RadioMenuFlyoutItem_rs2_themeresources_v1.xaml Removes legacy theme resource revision.
src/Uno.UI/UI/Xaml/Controls/RadioMenuFlyoutItem/RadioMenuFlyoutItem_rs4_themeresources_v1.xaml Removes legacy theme resource revision.
src/Uno.UI/UI/Xaml/Controls/RadioMenuFlyoutItem/RadioMenuFlyoutItem_rs5_themeresources_v1.xaml Removes legacy theme resource revision.
src/Uno.UI/UI/Xaml/Controls/MenuFlyout/MenuFlyout_themeresources.xaml Adds WinUI 3-aligned MenuFlyout theme resources/styles/templates.
src/Uno.UI/UI/Xaml/Controls/MenuFlyout/MenuFlyout_19h1_themeresources.xaml Removes legacy theme resource revision.
src/Uno.UI/UI/Xaml/Controls/MenuFlyout/MenuFlyout_rs1_themeresources.xaml Removes legacy theme resource revision.
src/Uno.UI/UI/Xaml/Controls/MenuFlyout/MenuFlyout_rs2_themeresources.xaml Removes legacy theme resource revision.
src/Uno.UI/UI/Xaml/Controls/MenuFlyout/MenuFlyout_rs4_themeresources.xaml Removes legacy theme resource revision.
src/Uno.UI/UI/Xaml/Controls/MenuFlyout/MenuFlyout_rs5_themeresources.xaml Removes legacy theme resource revision.
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_RadioMenuFlyoutItem.cs Adds a runtime test that reproduces the XAML attribute-order issue.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings May 12, 2026 13:59

Copilot AI 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.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 212116 has failed on Uno.UI - CI.

MartinZikmund and others added 5 commits May 13, 2026 21:11
)

When IsChecked="True" appears before GroupName in XAML attribute order,
the item was registered in the selection map under the empty group name
because GroupName was still its default value when IsChecked was applied.
A subsequent click on a sibling could not find the previously-checked
item under the real group name, so it was never unchecked.

Port the WinUI 3 OnLoaded handler that re-runs UpdateCheckedItemInGroup
once all XAML-applied properties are set. Also replace the unsafe C#
finalizer with a deterministic OnUnloaded handler that mirrors WinUI's.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Replace the WinUI 2.6-era theme resources with a verbatim 1:1 copy of
the latest WinUI 3 source (commit 69097129a8). Drop the four legacy
_rsX_themeresources_v1.xaml fallbacks, which targeted Win10 OS API
contracts and were superseded by the modern file at merge time.

Also bumps the Properties.cs MUX reference to the matching commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Replace the five legacy WinUI 2.x revisions (19h1, rs1, rs2, rs4, rs5)
with a verbatim 1:1 copy of the latest WinUI 3 source (commit
9d6fb15c08). This brings MenuFlyoutPresenter, MenuFlyoutItem,
MenuFlyoutSubItem, ToggleMenuFlyoutItem and SplitMenuFlyoutItem styles
in line with current WinUI, including the MenuFlyoutItemTextTrimming
resource that the synced RadioMenuFlyoutItem template now references.

Two Uno-specific extras from the legacy files are intentionally dropped:
- not_win:Glyph="&#xE73E;" SubItemChevron override (was in rs5)
- LanguageSwitcherMenuFlyoutItemPlaceholderThemeThickness (was in 19h1)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
When IsChecked is applied before GroupName (the common case being the XAML
attribute order IsChecked="True" GroupName="..."), the item ends up
registered in s_selectionMap under both the previous (default "") key and
the new key. The stale "" entry is never cleaned up, so an unrelated
RadioMenuFlyoutItem in the default empty group can incorrectly uncheck
this item when it becomes checked.

Track the GroupName actually used at registration time and erase the prior
entry (only when it still targets this instance) before re-registering;
also use the same key in OnUnloaded so we never remove another item's
registration. Wrapped in #if HAS_UNO since the same gap exists upstream;
tracked at microsoft/microsoft-ui-xaml#11098.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Excluded until upstream microsoft-ui-xaml#11098 is fixed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/issue19090 branch from c551400 to b57c52b Compare May 13, 2026 19:12
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 212432 has failed on Uno.UI - CI.

@MartinZikmund

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund
MartinZikmund merged commit ba5faf0 into master May 14, 2026
45 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/issue19090 branch May 14, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RadioMenuFlyoutItem does not de-select when IsChecked is explicitly set to True

4 participants