ItemsRepeater renders only the first item when no ScrollViewer in the visual tree under a popup
See original GitHub issueDescribe the bug
If there is no ScrollViewer
in the parent visual tree of an ItemsRepeater
, then it will render only the first item.
Steps to reproduce the bug
- Create a blank app, in the
MainPage
put:
MainPage.xaml
<Grid>
<Popup x:Name="popup" IsOpen="True">
<controls:ItemsRepeater x:Name="SUT" />
</Popup>
</Grid>
MainPage.xaml.cs
SUT.ItemsSource = Enumerable.Range(0, 10);
Expected behavior
As the Popup
is tall enough, we should see all 10 items.
Screenshots
Version Info
- Microsoft.UI.Xaml: 2.4.0-prerelease.200322001
- Windows: 1909 18363.778_
- Project’s target and min version: 18362
- Device: Desktop
Additional context
According to my tests, this is because in the ViewportManagerWithPlatformFeatures
, if we cannot find any scroller we init the viewport with an empty rect.
This drives the GetLayoutRealizationWindow
to return an empty Rect
.
This “window” is used by the FlowLayoutAlgorithm.ShouldContinueFillingUpSpace()
, which concludes that the viewport/window is full and stops the elements generation after the first one.
Note: this is not visible out of a Popup
as a normal Window
does have a ScrollViewer
in its “template”.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
Top GitHub Comments
Hi @ranjeshj , yes it works:
But it’s a valid use case to not use one. I would have fix it by myself, just I’m not a huge fan of C++ 😃
The issue is that if there is no scroller we don’t even subscribe to the
EffectiveViewportChanged
event. So except if you plan that a root control (like thePopup
in that case) implementsIScrollAnchorProvider
, I think that fixing #2102 would not fix this case.