Skip to content

ItemsPresenter header and footer changes should affect layout - #22781

Open
MartinZikmund wants to merge 6 commits into
masterfrom
dev/mazi/header-layout
Open

MartinZikmund wants to merge 6 commits into
masterfrom
dev/mazi/header-layout

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Mar 5, 2026 •

Copy link
Copy Markdown
Member

GitHub Issue: closes #20966

PR Type: 🐞 Bugfix

What is the current behavior? 🤔

Clearing a ListView.Header (or Footer) at runtime leaves the space it occupied behind. The same
Header cleared through Hot Reload does reclaim the space, which is what makes the bug look like a
layout-invalidation problem.

It isn't. The root cause is in ContentPresenter: once the implicit text block has been materialized
for non-View content, setting Content back to null only empties the text block's Text — the
TextBlock itself stays in the tree and keeps reserving a full line of height. So the header
ContentControl can never measure below one line, no matter how often the ItemsPresenter is
re-measured. WinUI materializes no visuals at all while the content is null and no template is set
(CContentPresenter::ApplyTemplate, dxaml/xcp/core/core/elements/ContentPresenter.cpp).

What is the new behavior? 🚀

  • ContentPresenter drops the implicit text block when Content goes back to null, matching WinUI.
    This fixes every ContentControl/ContentPresenter whose content is cleared, not just list headers.
  • ItemsPresenter.Header/Footer/HeaderTemplate/FooterTemplate are now AffectsMeasure, so a
    change 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 ContentControl inside MeasureOverride
(mirroring ItemsPresenter::MeasureOverride in WinUI). That has been dropped: it papered over the
ContentPresenter bug instead of fixing it, needed an ApplyTemplate() call inside MeasureOverride
to work at all, and regressed LayoutInformation.GetLayoutSlot() for the empty header/footer — Uno
never 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_Footer on every
platform 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_ContentPresenter and Given_ContentControl pass, including the two tests that were red in CI.

PR Checklist ✅

Please check if your PR fulfills the following requirements:

Copilot AI lite review requested due to automatic review settings March 5, 2026 08:09

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 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.AffectsMeasure to the Header, Footer, HeaderTemplate, and FooterTemplate dependency properties in ItemsPresenter so that changing them triggers a re-measure.
  • Added visibility management in ItemsPresenter.MeasureOverride to collapse HeaderContentControl/FooterContentControl when both content and template are null.
  • Added a runtime test When_Header_Set_To_Null_Layout_Space_Reclaimed to 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_Reclaimed is misleading because the test also verifies footer collapsing and header restoration (setting it to a new value after null). Consider a more descriptive name like When_Header_And_Footer_Set_To_Null_Are_Collapsed_And_Layout_Space_Reclaimed to better convey its scope.
		lv.Items.Add("1");

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

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 200000 found UI Test snapshots differences: android-28-net9: 20, android-28-net9-Snap: 26, ios: 6, ios-Snap: 43, skia-linux-screenshots: 55, skia-windows-screenshots: 65, wasm: 110, wasm-automated-net10.0-WinUI-Benchmarks-automated: 0, wasm-automated-net10.0-WinUI-Default-automated: 12, wasm-automated-net10.0-WinUI-RuntimeTests-0: 0, wasm-automated-net10.0-WinUI-RuntimeTests-1: 0, wasm-automated-net10.0-WinUI-RuntimeTests-2: 0

Details
  • android-28-net9: 20 changed over 758

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • FocusManager_GetFocusedElement_TextBoxMultiLine_LostFocus_Validation_FocusManager_-_LostFocus_-_TextBoxMultiLine_-_1_-_Initial_State
    • NativeCommandBar_Size_Uno_UI_Samples_Content_UITests_CommandBar_CommandBar_Dynamic
    • ProgressRing_IsEnabled_Running_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • ProgressRing_Visibility_Collapsed_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • SequentialAnimations_SamplesApp_Windows_UI_Xaml_Media_Animation_SequentialAnimationsPage
    • WebView_NavigateToAnchor_Uno_UI_Samples_Content_UITests_WebView_WebView_AnchorNavigation
    • When_Parent_PointerMoved_After_drag_on_non-scrolling_ScrollViewer
    • UpDownEnabledTest_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
    • When_ExtendedSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_Parent_PointerMoved_After_drag_on_ScrollViewer_-_touch
    • DecimalFormatterTest_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
    • Detereminate_ProgressRing_Validation75_[#FF0000_#008000_#008000_#008000]_Progress-Ring-Value-75
    • FocusManager_GetFocusedElement_TextBoxMultiLine_LostFocus_Validation_FocusManager_-_LostFocus_-_TextBoxMultiLine_-_2_-_Click_outside
    • FocusManager_GetFocusedElement_TextBoxMultiLine_LostFocus_Validation_Uno_UI_Samples_Content_UITests_FocusTests_FocusManager_GetFocus_Automated
    • When_NoSelectionWithItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_NoSelection_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_MultipleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • Detereminate_ProgressRing_Validation25_[#FF0000_#008000_#FF0000_#FF0000]_Progress-Ring-Value-25
    • ListView_ListViewWithHeader_InitializesTest_SamplesApp_Windows_UI_Xaml_Controls_ListView_HorizontalListViewGrouped
    • When_SingleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
  • android-28-net9-Snap: 26 changed over 1067

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Image_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_Basic_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_Basic
    • SwipeControl_MUXControlsTestApp_SwipeControlPage2_MUXControlsTestApp_SwipeControlPage2
    • TabView_MUXControlsTestApp_TabViewPage_MUXControlsTestApp_TabViewPage
    • MediaPlayerElement_Mini_player_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Minimal
    • MediaPlayerElement_Using_ogg_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Ogg_Extension
    • TeachingTip_UITests_Microsoft_UI_Xaml_Controls_TeachingTipTests_TeachingTipPage_UITests_Microsoft_UI_Xaml_Controls_TeachingTipTests_TeachingTipPage
    • CommandBarFlyout_MUXControlsTestApp_CommandBarFlyoutPage_MUXControlsTestApp_CommandBarFlyoutPage
    • Gesture_Recognizer_Pointer_Events_test_bench_UITests_Shared_Windows_UI_Input_GestureRecognizer_PointersEvents
    • ListView_ListView_With_ListViews_Count_Measure_UITests_Shared_Windows_UI_Xaml_Controls_ListView_ListView_With_ListViews_Count_Measure
    • Scrolling_MUXControlsTestApp_ScrollViewKeyboardAndGamepadNavigationPage_MUXControlsTestApp_ScrollViewKeyboardAndGamepadNavigationPage
    • MUX_UITests_Shared_Microsoft_UI_Xaml_Controls_TreeViewTests_TreeViewPage_UITests_Shared_Microsoft_UI_Xaml_Controls_TreeViewTests_TreeViewPage
    • Default_Uno_UI_Samples_Content_UITests_WebView_WebView_AnchorNavigation_Uno_UI_Samples_Content_UITests_WebView_WebView_AnchorNavigation
    • RatingControl_UITests_Microsoft_UI_Xaml_Controls_RatingControlTests_RatingControlPage_UITests_Microsoft_UI_Xaml_Controls_RatingControlTests_RatingControlPage
    • NavigationView_MUXControlsTestApp_NavigationViewRS4Page_MUXControlsTestApp_NavigationViewRS4Page
    • TextBlock_UITests_Shared_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_Layout_UITests_Shared_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_Layout
    • CommandBar_Examples_Uno_UI_Samples_Content_UITests_CommandBar_CommandBar_Examples
    • NavigationView_MUXControlsTestApp_NavigationViewTopNavOnlyPage_MUXControlsTestApp_NavigationViewTopNavOnlyPage
    • NavigationView_MUXControlsTestApp_NavigationViewTopNavPage_MUXControlsTestApp_NavigationViewTopNavPage
    • Transform_Basics_UITests_Shared_Windows_UI_Xaml_Media_Transform_Basics
    • UIElement_TransformToVisual_Simple_UITests_Shared_Windows_UI_Xaml_UIElementTests_TransformToVisual_Simple
  • ios: 6 changed over 213

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ProgressRing_IsEnabled_Running_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • SequentialAnimations_SamplesApp_Windows_UI_Xaml_Media_Animation_SequentialAnimationsPage
    • ListView_SelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • ProgressRing_Visibility_Collapsed_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • TextBox_UpdatedBinding_On_OneWay_Mode_UITests_Windows_UI_Xaml_Controls_TextBox_TextBox_Bindings
    • When_SingleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
  • ios-Snap: 43 changed over 986

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Brushes_GenericApp_Views_Content_UITests_ImageBrushTestControl_BorderImageBrushRelativeTransform_GenericApp_Views_Content_UITests_ImageBrushTestControl_BorderImageBrushRelativeTransform
    • Brushes_PathImageBrushfill_Uno_UI_Samples_UITests_ImageBrushTestControl_PathImageBrushfill
    • Default_SamplesApp_Wasm_Windows_UI_Xaml_Controls_ListView_ListView_IsSelected_SamplesApp_Wasm_Windows_UI_Xaml_Controls_ListView_ListView_IsSelected
    • Default_Uno_UI_Samples_Content_UITests_WebView_WebView_AnchorNavigation_Uno_UI_Samples_Content_UITests_WebView_WebView_AnchorNavigation
    • Icons_UITests_Shared_Windows_UI_Xaml_Controls_BitmapIconTests_BitmapIcon_Foreground_UITests_Shared_Windows_UI_Xaml_Controls_BitmapIconTests_BitmapIcon_Foreground
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Uno_UI_Samples_UITests_Image_Image_Stretch
    • Info_MUXControlsTestApp_InfoBarPage_MUXControlsTestApp_InfoBarPage
    • ListView_ListView_Aligned_Left_UITests_Shared_Windows_UI_Xaml_Controls_ListView_ListView_Aligned_Left
    • ColorPicker_ColorPickerSample_UITests_Microsoft_UI_Xaml_Controls_ColorPickerTests_ColorPickerSample
    • ContentControl_Uno_UI_Samples_Content_UITests_ContentControlTestsControl_ContentControl_Nested_TemplatedParent_Uno_UI_Samples_Content_UITests_ContentControlTestsControl_ContentControl_Nested_TemplatedParent
    • Grid_CenteredGridinGridwiththreefixedsizechildren_Uno_UI_Samples_Content_UITests_GridTestsControl_CenteredGridinGridwiththreefixedsizechildren
    • Image_Image_Stretch_None_Uno_UI_Samples_UITests_ImageTestsControl_Image_Stretch_None
    • Image_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Horizontal_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Horizontal
    • Image_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Vertical_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Vertical
    • NavigationView_MUXControlsTestApp_NavigationViewRS3Page_MUXControlsTestApp_NavigationViewRS3Page
    • NavigationView_MUXControlsTestApp_NavigationViewRS4Page_MUXControlsTestApp_NavigationViewRS4Page
    • Performance_UITests_Windows_UI_Xaml_Performance_Performance_1000ButtonsContinuousRendering_UITests_Windows_UI_Xaml_Performance_Performance_1000ButtonsContinuousRendering
    • SwipeControl_MUXControlsTestApp_SwipeControlPage2_MUXControlsTestApp_SwipeControlPage2
    • MediaPlayerElement_Mini_player_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Minimal
    • TextBlock_TextBlockMultilineInStarStackPanel_Uno_UI_Samples_Content_UITests_TextBlockControl_TextBlockMultilineInStarStackPanel
  • skia-linux-screenshots: 55 changed over 2314

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Buttons.png-dark
    • Buttons.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • DisplayInformation.png-dark
    • Examples.png-dark
    • Examples.png
    • ButtonClippingTestsControl.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • ImageBrush_Stretch.png-dark
    • ImageBrush_Stretch.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • DropDownButtonPage.png-dark
    • ListViewHeaderUpdate.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
  • skia-windows-screenshots: 65 changed over 2316

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ContentPresenter_Template.png-dark
    • ContentPresenter_Template.png
    • ContentPresenter_TextProperties.png-dark
    • ContentPresenter_TextProperties.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • EllipsemaskingEllipseGrid.png-dark
    • EllipsemaskingEllipseGrid.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • CalendarView_Theming.png-dark
    • ClipboardTests.png-dark
    • Buttons.png-dark
    • Buttons.png
    • DisplayInformation.png-dark
  • wasm: 110 changed over 1066

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • MUXControlsTestApp.CommandBarFlyoutPage
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListView_Expandable_Item_Large
    • UITests.Shared.Windows_UI_Xaml_Controls.ScrollViewerTests.ScrollViewer_Content_Smaller_Than_Viewport
    • UITests.Toolkit.ElevatedView_Levels
    • UITests.Toolkit.ElevatedView_Tester
    • UITests.Windows_UI_Xaml_Controls.CommandBar.CommandBar_Native_With_TextBox
    • UITests.Microsoft_UI_Xaml_Controls.RefreshContainerTests.RefreshContainerScrollTop
    • UITests.Microsoft_UI_Xaml_Controls.ScrollViewTests.KeyboardNavigationSample
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Shared.Windows_UI_Xaml_Media_Animation.SetTargetProperty
    • UITests.Windows_UI_Xaml_Controls.ListView.ListView_Selection_Events
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • UITests.Microsoft_UI_Xaml_Controls.InfoBadgeTests.InfoBadgePage
    • UITests.Shared.Windows_UI_Xaml_Controls.ComboBox.ComboBox_ComboBoxItem_Selection
    • UITests.Shared.Windows_UI_Xaml_Controls.ListView.ListView_Weird_Measure
    • UITests.Shared.Windows_UI_Xaml_Controls.TextBoxControl.TextBox_Binding_Null
    • UITests.Shared.Windows_UI_Xaml_Controls.TextBoxTests.TextBox_TextChanged
    • UITests.Windows_UI_Xaml_Controls.TextBox.TextBox_ClipboardMethods
    • UITests.Windows_UI_Xaml_Controls.ToolTip.ToolTip_DynamicContent
    • Uno.UI.Samples.Content.UITests.ButtonTestsControl.RadioButton_With_GroupName
  • wasm-automated-net10.0-WinUI-Benchmarks-automated: 0 changed over 1

  • wasm-automated-net10.0-WinUI-Default-automated: 12 changed over 877

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Default_StrokeThickness_MyPolygon
    • When_SingleSelectionWithItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • Default_StrokeThickness_MyEllipse
    • Default_StrokeThickness_MyLine
    • SequentialAnimations_SamplesApp_Windows_UI_Xaml_Media_Animation_SequentialAnimationsPage
    • Default_StrokeThickness_MyRect
    • ListView_SelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • Default_StrokeThickness_MyPolyline
    • TestProgressRing_InitialState_UITests_Microsoft_UI_Xaml_Controls_ProgressRing_WinUIProgressRing_Features
    • When_MultipleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • Default_StrokeThickness_MyPath
    • When_Theme_Changed_No_Crash_UITests_Windows_UI_Xaml_Controls_CalendarView_CalendarView_Theming
  • wasm-automated-net10.0-WinUI-RuntimeTests-0: 0 changed over 1

  • wasm-automated-net10.0-WinUI-RuntimeTests-1: 0 changed over 1

  • wasm-automated-net10.0-WinUI-RuntimeTests-2: 0 changed over 1

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/header-layout branch from d124a26 to 671aa0e Compare March 5, 2026 10:16
@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings March 5, 2026 15:24

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

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the stale This item has been marked as stale and will be closed if there is no activity. label May 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 10 days with no activity.

@github-actions github-actions Bot closed this May 31, 2026
@MartinZikmund MartinZikmund removed the stale This item has been marked as stale and will be closed if there is no activity. label Jun 22, 2026
@MartinZikmund MartinZikmund reopened this Jun 22, 2026
@github-actions

github-actions Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 3m 10s —— View job


PR Review

  • Read changed files
  • Analyze implementation correctness
  • Post inline review comments
  • Post review summary

Summary

The approach is correct — adding AffectsMeasure to the four Header/Footer DependencyProperties is the right fix for triggering re-measure when those properties change. The visibility-collapse logic in MeasureOverride is also sound in intent.

1 medium issue, 2 low issues found.

Medium: ApplyTemplate() on every measure pass (× 2)

Both headerCC.ApplyTemplate() and footerCC.ApplyTemplate() are called unconditionally on every MeasureOverride pass. Under the non-lifecycle path (Control.nonlifecycle.cs), ApplyTemplate() calls SetUpdateControlTemplate(forceUpdate: true) which always calls InvalidateMeasure() on the ContentControl — even after the template is already materialized. This schedules extra layout cycles on every subsequent measure of the ItemsPresenter. The fix is to guard each call with if (headerCC.TemplatedRoot is null) so it only runs once. See the inline suggestions.

Low: Dead variable footerHeightBefore

footerHeightBefore is captured but never used after its precondition assertion. Either use it in a post-null comparison or remove it.

Low: Missing [GitHubWorkItem] annotation

The new test covers issue #20966 but lacks the [GitHubWorkItem("https://github.com/unoplatform/uno/issues/20966")] attribute that the runtime-tests conventions require for traceability.


Validation evidence:

  • Code review assessment: AffectsMeasure additions are correct. ApplyTemplate() guard concern confirmed by reading Control.nonlifecycle.cs (line 49: SetUpdateControlTemplate(forceUpdate: true) → line 29: this.InvalidateMeasure() — always executed when forceUpdate=true).
  • Compile validation: not run in this environment.
  • Runtime validation: not run in this environment. Maintainers can run the new test via the /runtime-tests skill.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

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

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/header-layout branch from f539e77 to 45e91f3 Compare July 13, 2026 08:45
@github-actions

github-actions Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 1m 40s —— View job


PR Review

  • Read changed files
  • Check if previously identified issues were fixed
  • Post inline comments for remaining/new issues
  • Post review summary

Summary

The core fix is correct: adding AffectsMeasure to all four Header/Footer dependency properties is the right mechanism to trigger re-measure on property change, and collapsing the HeaderContentControl/FooterContentControl in MeasureOverride when content and template are both null correctly reclaims layout space.

The same 3 issues from the prior review (June 22) remain unaddressed in this sync.

Medium — ApplyTemplate() on every measure pass (×2)

ApplyTemplate() calls SetUpdateControlTemplate(forceUpdate: true), which unconditionally calls this.InvalidateMeasure() on the ContentControl (confirmed in Control.nonlifecycle.cs:29). Every MeasureOverride of ItemsPresenter therefore enqueues a new measure on both the header and footer ContentControl, producing perpetual extra layout cycles after the first pass. See inline suggestions to guard with if (headerCC.TemplatedRoot is null).

Low — footerHeightBefore dead local

The variable is used only in the pre-condition assertion and never compared after the footer is nulled. See inline suggestion.

Low — Missing [GitHubWorkItem] on the new test

Per Uno runtime-tests conventions, tests covering a specific issue need [GitHubWorkItem("https://github.com/unoplatform/uno/issues/20966")] for traceability. See inline suggestion.


Validation evidence:

  • Code review: AffectsMeasure additions are correct. ApplyTemplate() guard concern confirmed by reading Control.nonlifecycle.cs — SetUpdateControlTemplate(forceUpdate: true) always calls InvalidateMeasure().
  • Compile: not run.
  • Runtime: not run. Maintainers can run the new test via /runtime-tests Given_ItemsPresenter.When_Header_Set_To_Null_Layout_Space_Reclaimed.

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 230964 found UI Test snapshots differences: skia-linux-screenshots: 73, skia-windows-screenshots: 206

Details
  • skia-linux-screenshots: 73 changed over 2366

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Focus_FocusVisual_Properties.png-dark
    • DropDownButtonPage.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • ContextRequested.png-dark
    • Attributed_text_FontSize_Changing.png
    • Buttons.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • DynamicFont.png
    • Examples.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
  • skia-windows-screenshots: 206 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Buttons.png
    • ChatBox.png-dark
    • ChatBox.png
    • EllipsemaskingEllipseGrid.png-dark
    • Focus_FocusState.png-dark
    • Focus_FocusState.png
    • Grid_def_MinMaxValues.png-dark
    • Grid_def_MinMaxValues.png
    • Grid_in_Canvas.png-dark
    • Grid_in_Canvas.png
    • Grid_with_MinWidthColumns.png-dark
    • Grid_with_MinWidthColumns.png
    • EllipseAlignment2542_2547.png-dark
    • EllipseAlignment2542_2547.png
    • ImageAlignment2541.png-dark
    • ImageAlignment2541.png
    • ExpanderColorValidationPage.png-dark
    • Clipping652.png-dark
    • Clipping652.png
    • FocusManagerTest.png-dark

@unodevops

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

@MartinZikmund

Copy link
Copy Markdown
Member Author

Reworked after digging into the CI runtime-test failures.

What was failing in CI (build 230964): exactly two tests, on every platform (Windows/Linux/Linux-FB/macOS Skia, Android, iOS, WASM) — Given_ItemsPresenter.When_Small_Elements_Horizontal_Many_Margins_No_Header and _No_Footer, both on the header/footer layout-slot assertions (Expected 0,0,0,0 to approximate 496.0). The rest of the red checks are the same two tests × the retry policy. (The Screenshots Compare diffs in the earlier run are from the March build and unrelated.)

Why: the previous revision collapsed the header/footer ContentControl in MeasureOverride. Uno never flags layout storage for a collapsed element (WinUI does — CUIElement::MeasureInternal/ArrangeInternal call EnsureLayoutStorage() before the GetIsLayoutSuspended() early-out and still assign FinalRect), so LayoutInformation.GetLayoutSlot() came back as a default rect instead of the arrange rect those tests assert.

Root cause of the reported bug: not ItemsPresenter at all. Once ContentPresenter has materialized its implicit TextBlock, setting Content back to null only empties Text — the TextBlock stays in the tree and keeps reserving a line of height, so the header ContentControl can never measure below ~20px. Verified with a probe: desired=72,20 → after Content = null → desired=0,20, root=ImplicitTextBlock. WinUI creates no visuals at all while the content is null and no template is set (CContentPresenter::ApplyTemplate). Fixed there, which also fixes every other ContentControl/ContentPresenter whose content is cleared. With that in place the ItemsPresenter collapse (and the ApplyTemplate() inside MeasureOverride it required) is gone.

Runtime validation — Skia Desktop (Win32, Vulkan, 100% display scale):

  • Given_ItemsPresenter + Given_ContentPresenter + Given_ContentControl: 303 tests, 0 failures — including both tests that were red in CI.
  • Full Windows_UI_Xaml_Controls namespace (84 classes, run in 7 batches): ~1160 passing. Residual local failures (Given_ListViewBase.When_ThemeChange, Given_TextBlock.When_Inlines_Transitively_Change, 3 clipboard tests) reproduce identically with the ContentPresenter change reverted, so they are environmental/pre-existing here.

Note for a follow-up, out of scope for this PR: the collapsed-element layout-storage gap above is a real WinUI-parity divergence (LayoutInformation.GetLayoutSlot() and ActualWidth/ActualHeight on a collapsed element return defaults instead of the values Uno already stored).

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 231126 found UI Test snapshots differences: skia-linux-screenshots: 73, skia-windows-screenshots: 225

Details
  • skia-linux-screenshots: 73 changed over 2366

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • DropDownButtonPage.png-dark
    • Examples.png
    • Image_Margin_Large.png
    • ImageBrush_Stretch.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • Attributed_text_FontSize_Changing.png
    • Buttons.png
    • ContentControl_Inheritance.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
  • skia-windows-screenshots: 225 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Attributed_text_FontSize_Changing.png
    • ChatBox.png
    • ContentPresenter_NativeEmbedding_ZIndex.png
    • ExpanderColorValidationPage.png-dark
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • Buttons.png
    • EllipsemaskingEllipseGrid.png-dark
    • GetFocus.png-dark
    • GetFocus.png
    • Attributed_text_FontSize_Changing.png-dark
    • BitmapImage_vs_SvgImageSource.png
    • ButtonClippingTestsControl.png-dark
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • Grid_def_MinMaxValues.png-dark
    • Grid_def_MinMaxValues.png

@unodevops

Copy link
Copy Markdown
Contributor

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

@MartinZikmund MartinZikmund changed the title ItemsPresenter header and fooder changes should affect layout ItemsPresenter header and footer changes should affect layout Aug 31, 2026
@MartinZikmund
MartinZikmund changed the base branch from feature/breakingchanges to master September 2, 2026 20:04
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 231731 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2310, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Buttons.png-dark
    • Buttons.png
    • DisplayInformation.png-dark
    • ImageIconPage.png-dark
    • ContextRequested.png-dark
    • ContextRequested.png
    • Focus_FocusVisual_Properties.png-dark
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • Examples.png-dark
  • skia-windows-screenshots: 2310 changed over 2402

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppBar_KeyBoard.png-dark
    • ApplicationViewSpanningRectsPage.png
    • AutoBorderStretchwithrightmargin.png-dark
    • AutoSizedPathCentered.png
    • AutoSuggestBox_Reason.png-dark
    • BasicAutoSuggestBox.png
    • BeginTime_MultipleAnimations.png-dark
    • BitmapIcon_Foreground.png
    • Border_BorderThickness.png-dark
    • Border_BorderThickness.png
    • Border_CornerRadius_with_Opacity.png
    • Border_Corner_Overlap.png-dark
    • Border_With_Off_Centre_RotateTransform.png
    • Border_With_Off_Centre_ScaleTransform.png-dark
    • Button_Enabled_Control_Disabled.png-dark
    • Button_Enabled_Control_Disabled.png
    • CheckBox_States.png-dark
    • CheckBox_States.png
    • ComboBox_Description.png-dark
    • ComboBox_Description.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • UITests.Uno_Web.Http.CookieManagerTests
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools

@unodevops

Copy link
Copy Markdown
Contributor

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

@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.

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.

MartinZikmund and others added 6 commits October 3, 2026 10:43
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
Copilot AI lite review requested due to automatic review settings October 3, 2026 08:43
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/header-layout branch from 89579b3 to 1bb90a5 Compare October 3, 2026 08:43

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.

var host = new StackPanel { Width = 300 };
host.Children.Add(SUT);

await UITestHelper.Load(host);
ItemsSource = new[] { "Item 1", "Item 2" }
};

await UITestHelper.Load(lv);
Comment on lines +77 to 78
[GeneratedDependencyProperty(ChangedCallback = true, Options = FrameworkPropertyMetadataOptions.AffectsMeasure)]
public static DependencyProperty HeaderTemplateProperty { get; } = CreateHeaderTemplateProperty();
Comment on lines +96 to 97
[GeneratedDependencyProperty(ChangedCallback = true, Options = FrameworkPropertyMetadataOptions.AffectsMeasure)]
public static DependencyProperty FooterTemplateProperty { get; } = CreateFooterTemplateProperty();
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 1m 42s —— View job


PR Review

  • Read changed files
  • Analyze implementation correctness (AGENTS.md focus areas)
  • Check previously identified issues for regressions
  • Post inline review comments
  • Post review summary

Summary

Verdict: Ship. No new findings — the current diff (origin/master...HEAD, 4 files) is exactly the state the last two review rounds (Aug 22 and the Sep 8 human approval) already validated, and re-checking it against AGENTS.md didn't surface anything new.

What's in the diff:

  • ContentPresenter.cs: new else if (newValue is null && ContentTemplateRoot is ImplicitTextBlock) branch in OnContentChanged that nulls ContentTemplateRoot, matching WinUI's CContentPresenter::ApplyTemplate (no visuals while content is null and no template is set). This is the root-cause fix — confirmed by tracing UpdateContentTemplateRoot(): once ContentTemplateRoot is null and Content is null, no placeholder TextBlock is recreated, so no line-height is reserved. Correctly scoped to the ImplicitTextBlock case only — an explicit ContentTemplate is left alone, which matches WinUI (an explicit template can still render content-independent UI).
  • ItemsPresenter.cs: AffectsMeasure added to Header, Footer, HeaderTemplate, FooterTemplate DPs — correct and sufficient to re-measure ItemsPresenter itself on change, no collapse/ApplyTemplate() workaround left in MeasureOverride (that block was removed entirely in 1bb90a5a, resolving the ApplyTemplate()-every-measure-pass performance issue flagged in earlier rounds).
  • Tests: Given_ContentPresenter.When_Content_Cleared_Then_Space_Is_Reclaimed (the general regression test) and Given_ItemsPresenter.When_Header_And_Footer_Set_To_Null_Layout_Space_Reclaimed (the reported scenario), both carrying [GitHubWorkItem(...)]. The ItemsPresenter test is correctly gated behind #if HAS_UNO since it uses the internal HeaderContentControl/FooterContentControl and FindVisualChildByType, consistent with the rest of the file.

Cross-cutting checks (AGENTS.md): no event Action, no async-void, no new DP metadata mistakes, braces/tabs/style consistent with the surrounding file, root-cause-first (the earlier guard-only/collapse approach was explicitly dropped in favor of fixing ContentPresenter), no platform-suffix violations (both files are Skia-only shared code, as expected).

Cross-cutting concern (not a code defect): build 231731 (2026-09-03) reported 2310/2402 skia-windows-screenshots diffs — nearly the entire suite — versus 55–225 in prior runs on this same branch. That magnitude is far too broad to be caused by a ContentPresenter/ItemsPresenter layout change and looks like a CI image/baseline/environment issue rather than a regression from this PR. Worth a maintainer sanity-check before merge, but not something to act on in this diff.
— branch dev/mazi/header-layout

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 237155 found UI Test snapshots differences: skia-linux-screenshots: 119, skia-windows-screenshots: 151

Details
  • skia-linux-screenshots: 119 changed over 2454

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • DisplayInformation.png-dark
    • Examples.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • DynamicFont.png-dark
    • DynamicFont.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Image_AnimatedWebP.png-dark
    • Image_AnimatedWebP.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Focus_FocusVisual_Properties.png-dark
  • skia-windows-screenshots: 151 changed over 2456

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • CalendarView_Theming.png-dark
    • DisplayInformation.png-dark
    • Grid_Multi_Column_Span.png-dark
    • Grid_Multi_Column_Span.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • Examples.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Grid_left_column_Auto.png-dark
    • Grid_left_column_Auto.png
    • Grid_Margin_And_Padding.png-dark
    • Grid_Margin_And_Padding.png
    • Grid_middle_col_auto__bottom_row_auto.png-dark

@unodevops

Copy link
Copy Markdown
Contributor

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

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.

Reset ListView Header don't update Layout

5 participants