Virtualization Disabled Due to CanContentScroll is False
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:
However, when I intialize this UI screen, I see this line of error in the log:
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.
XAML:
Code: Select all
<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>
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).Virtualization disabled: items control CanContentScroll is False
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.
Re: Virtualization Disabled Due to CanContentScroll is False
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
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
Code: Select all
....
<ListBox.Template>
<ControlTemplate>
<ScrollViewer CanContentScroll="True"
Focusable="False"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</ListBox.Template>
....
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Virtualization Disabled Due to CanContentScroll is False
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.
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Virtualization Disabled Due to CanContentScroll is False
We improved the warning message for this specific situation (panel not inside a ScrollViewer) to make it more clear:
Hope this helps for future users facing this same problem.Virtualization disabled: ItemsPanel is not wrapped by a ScrollViewer
Re: Virtualization Disabled Due to CanContentScroll is False
beautiful, thank you guys for staying on top of it!
Who is online
Users browsing this forum: Google [Bot] and 17 guests