Repository navigation
fix: Bind implicit presenter content during measure - #25921
Conversation
|
Claude finished @MartinZikmund's task in 19s —— View job Review of #25921Verdict: fix-first (minor). The approach is sound. It mirrors Issues: 1 medium (inline), 0 high, 0 low. Cross-cutting notes
|
There was a problem hiding this comment.
🟡 Changes recommended
The regression test lacks the required GitHubWorkItem metadata linking it to issue #25920.
1 open issue
What changed in this PR
Fixes #25920 by initializing implicit ContentPresenter bindings during measure, so the first layout includes the templated parent’s content. This isolates the layout fix from the broader ListView/GridView presenter work in #25389.
Changes:
- Applies implicit bindings during measure while preserving the once-only
OnApplyTemplateguard. - Adds regression tests for first-measure content, delayed DataContext binding updates, and callback invocation count.
| File | Description |
|---|---|
src/Uno.UI/UI/Xaml/Controls/ContentPresenter/ContentPresenter.cs |
Initializes implicit bindings during template application from measure. |
src/Uno.UI.RuntimeTests/Microsoft/UI/Xaml/Controls/Given_ContentPresenter.cs |
Adds three regression tests and supporting test classes. |
Review effort: Balanced
|
The build 242767 found UI Test snapshots differences: Details
|
|
|
|
@Mergifyio backport release/stable/7.0 |
✅ Backports have been createdDetails
|
morning4coffe-dev
left a comment
There was a problem hiding this comment.
Setting up the implicit Content/ContentTemplate bindings during measure is the right fix. I compared it with CContentPresenter::ApplyTemplate (core/core/elements/ContentPresenter.cpp) and left one suggestion about where it runs, which would bring the order closer to WinUI. The bot's questions about the templated parent and [GitHubWorkItem] still need an answer.
|
This pull request is merged. |
A ContentPresenter without explicit Content/ContentTemplate bindings only picked up its templated parent's content on Loaded, after the first frame. The default ListViewItem template (a bare ListViewItemPresenter) therefore rendered its first frame with empty 40px items and realized 36 containers instead of 26. WinUI sets these bindings in CContentPresenter::ApplyTemplate, which runs from measure. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
dee7f4e to
91de77d
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
Claude finished @MartinZikmund's task in 22s —— View job Review of #25921Verdict: fix-first (minor). The fix is small and sound: it mirrors Issues: 2 medium (inline), 0 high, 0 low. Cross-cutting notes
|
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
Run the implicit Content/ContentTemplate bindings from ApplyTemplate, before the template expands, through an idempotent helper instead of latching the overridable OnApplyTemplate into measure. A templated parent assigned after the first measure is still picked up on Loaded. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNtzpwqXiaSHwvb2y5UA
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNtzpwqXiaSHwvb2y5UA
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
Claude finished @MartinZikmund's task in 14s —— View job Review of #25921 (latest push)Verdict: ship. 0 high, 0 medium, 0 low issues. I posted no inline comments. The latest commits address the earlier review points:
Notes
|
🤖 Addressed PR comments up to this point
|
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 247092 found UI Test snapshots differences: Details
|
Native WinUI CI showed CFrameworkElement::InvokeApplyTemplate calls OnApplyTemplate during measure. Restore the once-only call next to the default template bindings. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNtzpwqXiaSHwvb2y5UA
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNtzpwqXiaSHwvb2y5UA
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
Correction to my earlier replies: native WinUI (WinAppSDK runtime tests) shows
Given_ContentPresenter: 273/273 on Skia Desktop. The Desktop Windows |
|
Claude finished @MartinZikmund's task in 24s —— View job Review of #25921 (latest push, 507a7c0 / a178b13)Verdict: fix-first (minor). 0 high, 1 medium, 0 low. The finding is posted inline. The earlier Notes
|
| if (!_appliedTemplate) | ||
| { | ||
| _appliedTemplate = true; | ||
| OnApplyTemplate(); | ||
| } | ||
| } |
There was a problem hiding this comment.
This brings back the latch problem fixed in c310f2d. _appliedTemplate is set here on the first measure, even when GetTemplatedParent() is still null. OnApplyTemplate is what calls the "Loaded fallback" SetDefaultTemplateBindings(), and OnLoaded (~line 934) now skips it because of the latch. A presenter measured before its templated parent is assigned therefore never gets its implicit Content/ContentTemplate bindings. The comment on OnApplyTemplate says the fallback covers exactly that case, so it no longer holds.
Suggestion: keep the once-only OnApplyTemplate() call, but call SetDefaultTemplateBindings() unconditionally from OnLoaded (it's idempotent), or only latch when GetTemplatedParent() is not null. A test that measures a presenter, then attaches a templated parent, then loads it would cover this.
Also, the comment claims Uno's presenter never reports added visuals. If addedVisuals were ever true, InvokeApplyTemplate would call OnApplyTemplate() a second time. Consider guarding with !addedVisuals, or asserting it.
|
The build 247106 found UI Test snapshots differences: Details
|

GitHub Issue: closes #25920
PR Type:
🐞 Bugfix
What changed? 🚀
Split out of #25389 at reviewer request (Xiaoy312 / ajpinedam) so it can be reviewed and reverted on its own.
Previously, a
ContentPresenterwith no explicitContent/ContentTemplatebindings only hooked up its implicit bindings to the templated parent inOnApplyTemplate, run onLoaded. The first layout therefore rendered it empty (e.g. defaultListViewItemitems at 40px, 36 containers realized instead of 26).Now
ContentPresenteroverridesApplyTemplate(out bool addedVisuals)and runsOnApplyTemplate()once (guarded by_appliedTemplate) from measure, mirroringCContentPresenter::ApplyTemplatein WinUI.OnLoadedkeeps its guarded call, so subclassOnApplyTemplateoverrides still run exactly once.Runtime tests added in
Given_ContentPresenter:When_Implicit_Content_Binding_Presented_On_First_Measure(fails before the fix, passes after)When_Binding_DataContext_Set_After_First_Measure(explicit{Binding Foo}with DataContext set after first measure still shows and updates Foo)When_OnApplyTemplate_Called_Once_Across_Measure_And_LoadValidated on Skia Desktop: the 3 new tests pass, and the full
Given_ContentPresenterclass passes (273/273).PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT