-
I have enabled VirtualizingStackPanel in my WinUI 3 ListView, but it seems that virtualization is not working. In the InitializeComponent function of the window containing the ListView, I checked the virtualization status using the following code: bool IsVirtualizing = winrt::Microsoft::UI::Xaml::Controls::VirtualizingStackPanel::GetIsVirtualizing( MyListView() ); However, it returns false, indicating that virtualization is not enabled. Here is the XAML code for the ListView: <Grid>
<ListView x:Name="MyListView">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid> Could you please help me identify what might be wrong or what I might be missing to enable virtualization? void MainWindow::InitializeComponent( void )
{
MainWindowT<MainWindow>::InitializeComponent();
auto items = winrt::single_threaded_observable_vector<winrt::hstring>();
for( int i = 0; i < 10000; i++ )
{
items.Append( hstring{ std::to_wstring( i ) } );
}
MyListView().ItemsSource(items);
bool IsVrtualizing = winrt::Microsoft::UI::Xaml::Controls::VirtualizingStackPanel::GetIsVirtualizing( MyListView() );
if (IsVrtualizing)
{
OutputDebugString(L"\n IsVrtualizing = True\n");
}
else
{
OutputDebugString(L"\n IsVrtualizing = False\n");
}
} Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Stupid queestion, isn't listview virtualizing items by default in wiunui 3? What is VirtualizingStackPanel for? Just for curiosity. |
Beta Was this translation helpful? Give feedback.
It was stated on the ItemsStackPanel description page that virtualization is enabled, which has put my mind at ease. Thank you for listening to my concerns.