Repository navigation
ItemsPresenter header and footer changes should affect layout - #22781
MartinZikmund wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where dynamically setting ListView.Header or ListView.Footer to null at runtime did not reclaim the layout space occupied by the header/footer. The fix works by adding AffectsMeasure to the Header, Footer, HeaderTemplate, and FooterTemplate dependency properties of ItemsPresenter, and by collapsing the internal HeaderContentControl/FooterContentControl during MeasureOverride when there is no content or template set — matching the WinUI behavior.
Changes:
- Added
FrameworkPropertyMetadataOptions.AffectsMeasureto theHeader,Footer,HeaderTemplate, andFooterTemplatedependency properties inItemsPresenterso that changing them triggers a re-measure. - Added visibility management in
ItemsPresenter.MeasureOverrideto collapseHeaderContentControl/FooterContentControlwhen both content and template are null. - Added a runtime test
When_Header_Set_To_Null_Layout_Space_Reclaimedto verify that setting header/footer to null collapses the controls, and that re-setting them restores visibility.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Uno.UI/UI/Xaml/Controls/ItemsControl/ItemsPresenter.cs |
Adds AffectsMeasure to all four Header/Footer dependency properties; adds visibility-collapse logic in MeasureOverride for HeaderContentControl and FooterContentControl when content and template are both null |
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ItemsPresenter.cs |
Adds a runtime test verifying that setting ListView.Header/Footer to null collapses the respective content controls and that restoring header makes it visible again |
Comments suppressed due to low confidence (1)
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ItemsPresenter.cs:1205
- The test method name
When_Header_Set_To_Null_Layout_Space_Reclaimedis misleading because the test also verifies footer collapsing and header restoration (setting it to a new value after null). Consider a more descriptive name likeWhen_Header_And_Footer_Set_To_Null_Are_Collapsed_And_Layout_Space_Reclaimedto better convey its scope.
lv.Items.Add("1");
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22781/wasm-skia-net9/index.html |
|
The build 200000 found UI Test snapshots differences: Details
|
d124a26 to
671aa0e
Compare
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22781/wasm-skia-net9/index.html |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22781/wasm-skia-net9/index.html |
|
|
|
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days. |
|
This PR was closed because it has been stalled for 10 days with no activity. |
|
Claude finished @MartinZikmund's task in 3m 10s —— View job PR Review
SummaryThe approach is correct — adding 1 medium issue, 2 low issues found. Medium:
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22781/wasm-skia-net9/index.html |
|
|
f539e77 to
45e91f3
Compare
|
Claude finished @MartinZikmund's task in 1m 40s —— View job PR Review
SummaryThe core fix is correct: adding The same 3 issues from the prior review (June 22) remain unaddressed in this sync. Medium —
|
|
The build 230964 found UI Test snapshots differences: Details
|
|
|
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
Reworked after digging into the CI runtime-test failures. What was failing in CI (build Why: the previous revision collapsed the header/footer Root cause of the reported bug: not Runtime validation — Skia Desktop (Win32, Vulkan, 100% display scale):
Note for a follow-up, out of scope for this PR: the collapsed-element layout-storage gap above is a real WinUI-parity divergence ( |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22781/wasm-skia-net9/index.html |
|
The build 231126 found UI Test snapshots differences: Details
|
|
|
ItemsPresenter header and fooder changes should affect layoutItemsPresenter header and footer changes should affect layout
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22781/wasm-skia-net9/index.html |
|
The build 231731 found UI Test snapshots differences: Details
|
|
|
morning4coffe-dev
left a comment
There was a problem hiding this comment.
Invalidating measure when header/footer content or templates change, and removing only the implicit text visual when Content becomes null, are consistent with the desired layout behavior. WinUI's CContentPresenter::ApplyTemplate expands an explicit content template when present, but creates the implicit content visual only when content is non-null. The null/non-null round-trip case protects the relevant public contract; the ItemsPresenter-specific cases cover Uno's implementation details.
Guard the ItemsPresenter header/footer ApplyTemplate() calls with a TemplatedRoot null check. On the non-enhanced lifecycle, ApplyTemplate() always calls InvalidateMeasure(), so calling it on every measure pass re-dirtied the header/footer ContentControl each time. Also link the new test to its issue and drop dead locals. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01GKBgQoAmRmaFoXXZr93iLB
Setting Content back to null left the implicit text block in place, with only its Text emptied, so the presenter kept reserving a line of height. WinUI materializes no visuals at all while the content is null and no template is set (CContentPresenter::ApplyTemplate), so drop the placeholder with the content. This is the root cause of a ListView Header/Footer reset not reclaiming its layout space: the header ContentControl never shrank below one text line. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01NqJGkhKztnsWLQtVYPgnfY
The collapse mirrored WinUI's ItemsPresenter::MeasureOverride, but it papered over the ContentPresenter bug rather than fixing it, and it needed an ApplyTemplate() call inside MeasureOverride to work at all. With the presenter fixed, an empty header/footer already measures to zero. It also regressed layout slots: Uno never flags layout storage for a collapsed element, so LayoutInformation.GetLayoutSlot() on the empty header/footer returned a default rect instead of the arrange rect WinUI reports, breaking When_Small_Elements_Horizontal_Many_Margins_No_Header/_No_Footer. Also stop walking the ListView template by hand in the new test. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01NqJGkhKztnsWLQtVYPgnfY
89579b3 to
1bb90a5
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
One or more issues must be addressed before approval.
Review effort: Lite
Findings: 4
Open (4)
Resolved since last review (5)
AssertingActualHeightequals exactly0.0can be flaky due to subpixel layout, rounding, or… AssertingActualHeightequals exactly0.0can be flaky due to subpixel layout, rounding, or… This test hard-codes the control template structure (ListView root child isBorder, its child is… CallingApplyTemplate()from insideMeasureOverridecan cause avoidable extra layout passes… This runs on every measure and unconditionally assignsVisibilityeach time, which can trigger…
| var host = new StackPanel { Width = 300 }; | ||
| host.Children.Add(SUT); | ||
|
|
||
| await UITestHelper.Load(host); |
| ItemsSource = new[] { "Item 1", "Item 2" } | ||
| }; | ||
|
|
||
| await UITestHelper.Load(lv); |
| [GeneratedDependencyProperty(ChangedCallback = true, Options = FrameworkPropertyMetadataOptions.AffectsMeasure)] | ||
| public static DependencyProperty HeaderTemplateProperty { get; } = CreateHeaderTemplateProperty(); |
| [GeneratedDependencyProperty(ChangedCallback = true, Options = FrameworkPropertyMetadataOptions.AffectsMeasure)] | ||
| public static DependencyProperty FooterTemplateProperty { get; } = CreateFooterTemplateProperty(); |
|
Claude finished @MartinZikmund's task in 1m 42s —— View job PR Review
SummaryVerdict: Ship. No new findings — the current diff ( What's in the diff:
Cross-cutting checks (AGENTS.md): no Cross-cutting concern (not a code defect): build 231731 (2026-09-03) reported 2310/2402 |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22781/wasm-skia-net9/index.html |
|
The build 237155 found UI Test snapshots differences: Details
|
|
|

GitHub Issue: closes #20966
PR Type: 🐞 Bugfix
What is the current behavior? 🤔
Clearing a
ListView.Header(orFooter) at runtime leaves the space it occupied behind. The sameHeadercleared through Hot Reload does reclaim the space, which is what makes the bug look like alayout-invalidation problem.
It isn't. The root cause is in
ContentPresenter: once the implicit text block has been materializedfor non-
Viewcontent, settingContentback tonullonly empties the text block'sText— theTextBlockitself stays in the tree and keeps reserving a full line of height. So the headerContentControlcan never measure below one line, no matter how often theItemsPresenterisre-measured. WinUI materializes no visuals at all while the content is
nulland no template is set(
CContentPresenter::ApplyTemplate,dxaml/xcp/core/core/elements/ContentPresenter.cpp).What is the new behavior? 🚀
ContentPresenterdrops the implicit text block whenContentgoes back tonull, matching WinUI.This fixes every
ContentControl/ContentPresenterwhose content is cleared, not just list headers.ItemsPresenter.Header/Footer/HeaderTemplate/FooterTemplateare nowAffectsMeasure, so achange re-measures the presenter itself rather than relying on the child's invalidation reaching it.
An earlier revision of this PR collapsed the header/footer
ContentControlinsideMeasureOverride(mirroring
ItemsPresenter::MeasureOverridein WinUI). That has been dropped: it papered over theContentPresenterbug instead of fixing it, needed anApplyTemplate()call insideMeasureOverrideto work at all, and regressed
LayoutInformation.GetLayoutSlot()for the empty header/footer — Unonever flags layout storage for a collapsed element, so the slot came back as a default rect instead of
the arrange rect WinUI reports. That broke
Given_ItemsPresenter.When_Small_Elements_Horizontal_Many_Margins_No_Header/_No_Footeron everyplatform in CI.
Tests
Given_ContentPresenter.When_Content_Cleared_Then_Space_Is_Reclaimed— the root-cause regression test.Given_ItemsPresenter.When_Header_And_Footer_Set_To_Null_Layout_Space_Reclaimed— the reported scenario.Validated at runtime on Skia Desktop (Win32, 100% scale): 303 tests across
Given_ItemsPresenter,Given_ContentPresenterandGiven_ContentControlpass, including the two tests that were red in CI.PR Checklist ✅
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.