Skip to content

fix: Bind implicit presenter content during measure - #25921

Merged
MartinZikmund merged 6 commits into
masterfrom
dev/mazi/contentpresenter-measure-binding
Nov 18, 2026
Merged

MartinZikmund merged 6 commits into
masterfrom
dev/mazi/contentpresenter-measure-binding

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

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 ContentPresenter with no explicit Content/ContentTemplate bindings only hooked up its implicit bindings to the templated parent in OnApplyTemplate, run on Loaded. The first layout therefore rendered it empty (e.g. default ListViewItem items at 40px, 36 containers realized instead of 26).

Now ContentPresenter overrides ApplyTemplate(out bool addedVisuals) and runs OnApplyTemplate() once (guarded by _appliedTemplate) from measure, mirroring CContentPresenter::ApplyTemplate in WinUI. OnLoaded keeps its guarded call, so subclass OnApplyTemplate overrides 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_Load

Validated on Skia Desktop: the 3 new tests pass, and the full Given_ContentPresenter class passes (273/273).

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT

Copilot AI balanced review requested due to automatic review settings November 2, 2026 08:38
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 19s —— View job


Review of #25921

Verdict: fix-first (minor). The approach is sound. It mirrors CContentPresenter::ApplyTemplate, it is small, and it has red/green runtime tests.

Issues: 1 medium (inline), 0 high, 0 low.

Cross-cutting notes

  • Code style, comments and Conventional Commits all look fine.
  • I reviewed by inspection only. I did not build or run tests, so the PR's Skia Desktop results (273/273) are unverified by me.
  • The "called once" guarantee is the main risk. _appliedTemplate is only guarded in ContentPresenter, while InvokeApplyTemplate has its own OnApplyTemplate() call path.

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.

🟡 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 OnApplyTemplate guard.
  • 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

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 242767 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png
    • Accessibility_ScreenReader.png-dark
    • AppBarToggleButtonTest.png
    • AppBarButtonTest.png
    • AppXamlDefinedResources.png-dark
    • AppBar_KeyBoard.png
    • Attributed_text_FontSize_Changing.png
    • Application_DispatcherShutdownMode.png-dark
    • AuthenticationBroker_Cancel.png
    • AppWindowPositionAndSize.png
    • AutomationPropertiesExtensions_Role.png-dark
    • Arrange_Performance01.png-dark
    • AutoSizedTopLeft.png
    • Attributed_text_Simple.png
    • AutoSuggestBox_Description.png
    • AuthenticationBroker_Demo.png
    • AutoSuggestBox_Reason.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutoSuggestBox_Reason.png
    • AutomationProperties_AutomationId.png
  • skia-windows-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png
    • AnimatedBackVisualSourceSamplePage.png
    • AppBarButtonWithIconTest.png
    • ApplicationViewMode.png
    • AppWindowFeatures.png-dark
    • AppWindowTitleBar Properties.png
    • Attributed_text_FontSize_Changing.png
    • AutoBorderStretchwithbottommargin.png-dark
    • AutomationPropertiesExtensions_Role.png
    • AutomationProperties_AutomationId.png-dark
    • AutoSuggestBox_Keyboard.png-dark
    • AutoSuggestBox_Keyboard.png
    • BasicAutoSuggestBox.png-dark
    • BasicAutoSuggestBox.png
    • Battery.png-dark
    • Battery.png
    • BindableDrawerLayout_ChangePane.png-dark
    • BindableDrawerLayout_ChangePane.png
    • BitmapImage_vs_SvgImageSource.png-dark
    • BitmapImage_vs_SvgImageSource.png

@unodevops

Copy link
Copy Markdown
Contributor

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

@MartinZikmund MartinZikmund added the 7.0 PRs only. For issues, use the Release field. label Nov 4, 2026
@MartinZikmund

Copy link
Copy Markdown
Member Author

@Mergifyio backport release/stable/7.0

@mergify

mergify Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/7.0

✅ Backports have been created

Details

@morning4coffe-dev morning4coffe-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

MartinZikmund and others added 2 commits November 17, 2026 15:16
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
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/contentpresenter-measure-binding branch from dee7f4e to 91de77d Compare November 17, 2026 14:16
Copilot AI balanced review requested due to automatic review settings November 17, 2026 14:16

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.

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.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 22s —— View job


Review of #25921

Verdict: fix-first (minor). The fix is small and sound: it mirrors CContentPresenter::ApplyTemplate and has red/green runtime tests.

Issues: 2 medium (inline), 0 high, 0 low.

Cross-cutting notes

  • This was a review by inspection only. I did not build or run tests, so the 273/273 Skia result is unverified by me.
  • The earlier bot concern about a double OnApplyTemplate looks unlikely to occur. ContentPresenter isn't a Control, so addedVisuals should stay false. A template-bearing test would confirm it.
  • Code style, comments and Conventional Commits look fine.
  • The CI screenshot-comparison failures (2458 changed) and the failed Uno.UI CI build are not explained by this diff. Please check whether they are infrastructure noise before merging.

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

MartinZikmund and others added 2 commits November 17, 2026 15:49
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
Copilot AI balanced review requested due to automatic review settings November 17, 2026 14:53

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.

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.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • ApplyTemplate now calls a private, idempotent SetDefaultTemplateBindings() before base.ApplyTemplate. That is the shape @morning4coffe-dev proposed. The existing DefaultValue && !IsPropertyTemplateBound guards make repeat calls safe.
  • A null templated parent at first measure no longer latches anything. The helper simply runs again on a later measure or on Loaded.
  • The virtual OnApplyTemplate is no longer called from measure. The existing _appliedTemplate guard in OnLoaded still gives subclass overrides exactly one call, so the double-call concern no longer applies.
  • [GitHubWorkItem(".../issues/25920")] is now present on the regression tests (Given_ContentPresenter.cs:526, :543 and :570).

Notes

  • Code review assessment only. I did not build or run tests, so the 273/273 Skia Desktop result is the author's and unverified by me.
  • The "called once" runtime test is worth re-running against the refactor, since the implementation behind it changed.
  • The 2458 screenshot diffs and the failed Uno.UI CI build on the old run aren't explained by this small diff. Confirm they are infrastructure noise on the latest run before merging.

@MartinZikmund

Copy link
Copy Markdown
Member Author

🤖 Addressed PR comments up to this point

  • @morning4coffe-dev (review): the WinUI ApplyTemplate suggestion is in c310f2d. The bindings now run from an idempotent SetDefaultTemplateBindings() called by ApplyTemplate (no latch, no OnApplyTemplate from measure). The bot's templated-parent and [GitHubWorkItem] questions are answered inline and fixed in b569bd5.
  • The backport request (@mergifyio backport release/stable/7.0) is unchanged; Mergify acts on it at merge.

@unoplatform unoplatform deleted a comment from unodevops Nov 17, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 247092 found UI Test snapshots differences: skia-linux-screenshots: 248, skia-windows-screenshots: 255

Details
  • skia-linux-screenshots: 248 changed over 2496

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • AnimatedVisualsTestbedPage.png
    • AutomationProperties_AutomationId.png
    • AutomationProperties_StructureAndProps.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • Accessibility_Showcase.png-dark
    • AutomationProperties_AutomationId.png-dark
    • Basics.png-dark
    • Basics.png
    • BreadcrumbBarPage.png-dark
  • skia-windows-screenshots: 255 changed over 2496

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AutomationProperties_StructureAndProps.png-dark
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • Accessibility_Showcase.png-dark
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • AnimatedVisualsTestbedPage.png

MartinZikmund and others added 2 commits November 17, 2026 17:19
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
Copilot AI balanced review requested due to automatic review settings November 17, 2026 16:22

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.

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.

@MartinZikmund

Copy link
Copy Markdown
Member Author

Correction to my earlier replies: native WinUI (WinAppSDK runtime tests) shows OnApplyTemplate does run during measure. CFrameworkElement::InvokeApplyTemplate calls it right after ApplyTemplate (framework.cpp, winui3/release/2.5.1).

  • a178b13^ (fix): the presenter again calls OnApplyTemplate once from measure, shared with the Loaded fallback. The default bindings still run first on every ApplyTemplate, so a templated parent assigned after the first measure still gets them.
  • a178b13 (test): When_OnApplyTemplate_Called_Once_Across_Measure_And_Load now expects 1 after measure, matching WinUI. When_Binding_DataContext_Set_After_First_Measure now puts the binding on the templated parent: a ContentPresenter's own DataContext is its Content (CContentPresenter::SetDataContext), so binding its own Content broke on WinUI.

Given_ContentPresenter: 273/273 on Skia Desktop. The Desktop Windows Given_TextBox.When_Touch_Selection_* failures are unrelated; they also fail on master (build 247033).

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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 SetDefaultTemplateBindings() refactor in c310f2d and the [GitHubWorkItem] attributes still look good. The newest commit (507a7c0) adds a _appliedTemplate-latched OnApplyTemplate() call back into ApplyTemplate. This partly undoes the fix for the earlier templated-parent concern, because the Loaded fallback is now skipped once measure has latched the flag.

Notes

  • Code review assessment only. I did not build or run tests, so the author's 273/273 Skia Desktop result is unverified by me.
  • The reworked When_Binding_DataContext_Set_After_First_Measure now sets the binding on a ContentControl that already has its templated parent at first measure. It no longer covers a parent assigned after the first measure. A test for that case would catch the regression above.
  • The 2458 screenshot diffs were on an older run. The latest run shows about 250 diffs, so please confirm those are expected or noise.

Comment on lines +609 to +614
if (!_appliedTemplate)
{
_appliedTemplate = true;
OnApplyTemplate();
}
}

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.

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.

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 247106 found UI Test snapshots differences: skia-linux-screenshots: 248, skia-windows-screenshots: 285

Details
  • skia-linux-screenshots: 248 changed over 2496

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_Showcase.png
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • AnimatedBackVisualSourceSamplePage.png
    • Accessibility_Showcase.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • AnimatedVisualsTestbedPage.png
    • BasicAcrylicBrushTest2.png-dark
    • Basics.png-dark
    • BasicAcrylicBrushTest2.png
    • Basics.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
  • skia-windows-screenshots: 285 changed over 2496

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png-dark
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • Basics.png-dark
    • Basics.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • AnimatedVisualsTestbedPage.png-dark
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • Accessibility_Showcase.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.0 PRs only. For issues, use the Release field.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ContentPresenter implicit Content binding only applies on Loaded, so the first frame renders empty (WinUI applies it during measure)

5 participants