lukeyen
Topic Author
Posts: 7
Joined: 22 Dec 2021, 06:00

Virtualization Disabled Due to CanContentScroll is False

23 Jun 2022, 07:04

Hey folks, have been experimenting with Virtualization with a somewhat large data set (~350 items) but was running into some issues. Relatively new to Noesis/WPF in general, so would love to see if anyone could point out where I am doing things incorrectly.

XAML:
       <ListBox x:Name="CardsContainer"
                 ItemsSource="{Binding viewModel.cards, Mode=OneWay}"
                 Grid.Row="3"
                 VirtualizingPanel.IsVirtualizing="True"
                 VirtualizingPanel.VirtualizationMode="Recycling"
                 ScrollViewer.CanContentScroll="True">

          <ListBox.Template>
            <ControlTemplate>
              <ItemsPresenter ScrollViewer.CanContentScroll="True"/>
            </ControlTemplate>
          </ListBox.Template>

          <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
              <VirtualizingStackPanel Orientation="Vertical"
                                      Margin="5,20,20,20"                                      
                                      VirtualizingPanel.VirtualizationMode="Recycling"/>
            </ItemsPanelTemplate>
          </ItemsControl.ItemsPanel>


          <ItemsControl.ItemTemplate>
            <DataTemplate>
              <ContentControl Style="{DynamicResource ContentCardContainer}" Visibility="{Binding Path=CardVisibility, Converter={StaticResource BoolVizConverter}}">
                <comp:CardComponent/>
              </ContentControl>
            </DataTemplate>
          </ItemsControl.ItemTemplate>

        </ListBox>
However, when I intialize this UI screen, I see this line of error in the log:
Virtualization disabled: items control CanContentScroll is False
When I checked the callstack, I see the log was initiated from VirtualizingStackPanel::CheckVirtualization. And the memory shots up by ~150MB further indicating that Virtualization isn't turned on (each card is almost half a MB and there are ~350 cards).
I have also double checked in the Noesis Inspector and have confirmed all the places that I could set CanContentScroll are indeed all set to True. Not sure if I am missing something obvious or there is some gotcha that I missed where it overwrites/reset CanContentScroll back to False.

Would love some advices on how I could further debug this.
 
lukeyen
Topic Author
Posts: 7
Joined: 22 Dec 2021, 06:00

Re: Virtualization Disabled Due to CanContentScroll is False

23 Jun 2022, 18:27

Update: Figured out my issue with a pair of well rested eyes this morning =)

In the case I shared previously, I was missing a <ScrollViewer> wrapped around the <ItemsPresenter>. As soon as I added that, Virtualization was no longer turned off, entering the screen was instantaneous, and memory usage went up in negligible amount only (less than 1MB versus ~150MB).

Updated XAML code
.... 
                <ListBox.Template>
                    <ControlTemplate>
                        <ScrollViewer CanContentScroll="True"
                                      Focusable="False"
                                      HorizontalScrollBarVisibility="Auto"
                                      VerticalScrollBarVisibility="Auto"
                                      HorizontalAlignment="Stretch"
                                      VerticalAlignment="Stretch">
                            <ItemsPresenter/>
                        </ScrollViewer>
                    </ControlTemplate>
                </ListBox.Template>
....
 
User avatar
sfernandez
Site Admin
Posts: 2572
Joined: 22 Dec 2011, 19:20

Re: Virtualization Disabled Due to CanContentScroll is False

23 Jun 2022, 19:14

Thanks for the update. As you found a VirtualizingStackPanel needs to be placed inside a ScrollViewer in ItemsControl's template in order to virtualize the items.
 
User avatar
sfernandez
Site Admin
Posts: 2572
Joined: 22 Dec 2011, 19:20

Re: Virtualization Disabled Due to CanContentScroll is False

23 Jun 2022, 19:48

We improved the warning message for this specific situation (panel not inside a ScrollViewer) to make it more clear:
Virtualization disabled: ItemsPanel is not wrapped by a ScrollViewer
Hope this helps for future users facing this same problem.
 
lukeyen
Topic Author
Posts: 7
Joined: 22 Dec 2021, 06:00

Re: Virtualization Disabled Due to CanContentScroll is False

25 Jun 2022, 08:41

beautiful, thank you guys for staying on top of it!

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests