Skip to content

fix(navigationbar): render UIElement Content on Simple primary commands - #1653

Merged
kazo0 merged 2 commits into
mainfrom
dev/vs/navbar-appbarbutton-content-1652
Sep 30, 2026
Merged

kazo0 merged 2 commits into
mainfrom
dev/vs/navbar-appbarbutton-content-1652

Conversation

@vatsashah45

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #1652

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

In the Simple toolkit theme, an AppBarButton in NavigationBar.PrimaryCommands whose Content is a UIElement (e.g. a Grid wrapping a TextBlock) renders an empty slot. String Content and Icon render fine.

Uno's AppBarButton (AppBarButton.uno.cs, SetupContentUpdate) looks up the template part named Content and force-sets it to Icon ?? Content. The toolkit's own SimpleAppBarButtonStyle in src/library/Uno.Toolkit.Simple/Styles/Controls/NavigationBar.xaml used that name for the icon presenter inside the Viewbox that collapses when Icon is null. With no Icon, Uno moves the user's Content into that collapsed presenter; a UIElement can only have one visual parent, so it is torn out of the visible ContentPresenter. A string survives because it can be displayed by two presenters at once. Same root cause as unoplatform/Uno.Themes#1735 (fixed in unoplatform/Uno.Themes#1736); the toolkit copy of the style needs the same fix because the NavigationBar resolves its own SimpleAppBarButtonStyle at parse time.

What is the new behavior?

  • SimpleAppBarButtonStyle: the icon presenter is renamed to IconPresenter (plus its three visual-state setters), with a comment explaining why the part must not be named Content. SimpleMainCommandStyle is left untouched since that template never displays Content (it shows the back-arrow PathIcon when Icon is null).
  • New runtime test NavigationBarTests.Simple_PrimaryCommands_Render_Icon_And_Content_Variants (in NavigationBarTests.PrimaryCommands.cs, partial of the existing class): a Simple-themed NavigationBar with Icon-only, string-Content, UIElement-Content and Icon + Content primary commands; each marker element must be inside its button, not under a collapsed ancestor, and laid out. Red/fix/green: fails on main, passes with the fix. The whole NavigationBar* filter (19 tests) passes on the Simple desktop head in Release.
  • specs/lessons.md records the template-part hijack.

Material v2 primary commands are not touched here: they are BasedOn Uno.Themes' MaterialAppBarButtonStyle, so they pick up the fix once UnoThemesVersion is bumped to a build containing Uno.Themes#1736.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Tested the changes where applicable:
    • Skia Desktop (runtime tests, Release)
  • Updated the documentation as needed:
    • No doc change required (no style key or lightweight-styling key changed)
  • Runtime Tests and/or UI Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Contains NO breaking changes
  • Associated with an issue (GitHub or internal)
  • Commits must be following the Conventional Commits specification.

Other information

Two pre-existing local-dev issues noticed while validating, both out of scope:

  • A Debug desktop build of the Simple sample head terminates at startup on the Debug.Assert in SafeArea.CreateWeakHandler, because static lambdas have a non-null Target (the compiler's <>c singleton). Release is unaffected. Similar to what fix(responsive): reconnect a re-parented host instead of tearing down #1647 fixed for ResponsiveExtensions.
  • The XAML Styler passive check fails on Uno.Toolkit.Simple/Styles/Controls/NavigationBar.xaml on main as well; formatting it would rewrite the whole file, so this PR keeps the file's existing style.

🤖 Generated with Claude Code

Uno's AppBarButton looks up the template part named "Content" and
force-sets it to `Icon ?? Content`. The toolkit's own
SimpleAppBarButtonStyle (Uno.Toolkit.Simple NavigationBar.xaml) used
that name for the icon presenter inside the Viewbox that collapses when
no Icon is set, so a UIElement assigned to Content on a NavigationBar
primary command was re-parented into the collapsed presenter and never
rendered. Strings survived because they can be shown by two presenters.

- Rename the icon presenter to IconPresenter (and its visual-state
  setters); SimpleMainCommandStyle is untouched since it never displays
  Content.
- Add NavigationBarTests.Simple_PrimaryCommands_Render_Icon_And_Content_Variants
  (red before the fix, green after) covering Icon-only, string Content,
  UIElement Content and Icon + Content primary commands.
- Record the lesson in specs/lessons.md.

Same root cause as unoplatform/Uno.Themes#1735 (fixed in Uno.Themes#1736).

Fixes #1652

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 236319 has failed on Uno Toolkit - CI.

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

@vatsashah45 vatsashah45 self-assigned this Sep 30, 2026
@kazo0

kazo0 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

@Mergifyio backport servicing/10.0

@mergify

mergify Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

backport servicing/10.0

✅ Backports have been created

Details

Cherry-pick of 439331f has failed:

On branch mergify/bp/servicing/10.0/pr-1653
Your branch is up to date with 'origin/servicing/10.0'.

You are currently cherry-picking commit 439331f.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   src/Uno.Toolkit.RuntimeTests/Tests/NavigationBarTests.PrimaryCommands.cs
	modified:   src/library/Uno.Toolkit.Simple/Styles/Controls/NavigationBar.xaml

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   specs/lessons.md

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@kazo0
kazo0 merged commit 439331f into main Sep 30, 2026
24 checks passed
@kazo0
kazo0 deleted the dev/vs/navbar-appbarbutton-content-1652 branch September 30, 2026 14:58
vatsashah45 added a commit that referenced this pull request Oct 3, 2026
- specs/lessons.md: drop the committed conflict markers and the main-only
  entries the cherry-pick dragged in; keep servicing's file plus the one
  new AppBarButton lesson from #1653.
- NavigationBarTests.PrimaryCommands.cs: declare the partial without an
  access modifier (NavigationBarTests is internal on servicing, public on
  main; CS0262), and replace Assert.IsNotNull with an explicit null guard
  since servicing's MSTest does not annotate it for nullable flow (CS8604
  under warnings-as-errors).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
agneszitte pushed a commit that referenced this pull request Oct 6, 2026
…ds (backport #1653) (#1659)

* fix(navigationbar): render UIElement Content on Simple primary commands (#1653)

Co-authored-by: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 439331f)

# Conflicts:
#	specs/lessons.md

* fix(backport): resolve servicing/10.0 conflicts for #1653

- specs/lessons.md: drop the committed conflict markers and the main-only
  entries the cherry-pick dragged in; keep servicing's file plus the one
  new AppBarButton lesson from #1653.
- NavigationBarTests.PrimaryCommands.cs: declare the partial without an
  access modifier (NavigationBarTests is internal on servicing, public on
  main; CS0262), and replace Assert.IsNotNull with an explicit null guard
  since servicing's MSTest does not annotate it for nullable flow (CS8604
  under warnings-as-errors).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Vatsa Shah <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

[Simple] NavigationBar primary commands do not render AppBarButton.Content when it is a UIElement

3 participants