0

I would like to have your advise with ListView in a WinUI 3 project (Desktop).
I have a search box where the user can enter keywords and according to them, the results are displayed in a listview. The listview can contain 0 to more than 10000 entries to display. When the number of items to display is very large, the listview can take more than 6 sec to display the results.

I wonder why it takes so long when the listview handles data virtualization (as if the listview renders all results even though they are not displayed)

I found the following articles in which the authors talk about lazy loading:

ListView Scrolling

https://platform.uno/blog/lazy-loading-functionality-uno-wasm/

Do you think it is necessary to implement this type of operation when you know that the number of results can be high or am I using the listview wrong?

I use the following code to declare my listview:

<CollectionViewSource x:Name="SearchViewResults"
                                  Source="{x:Bind ViewModel.ResultItems}"
                                  IsSourceGrouped="True" />
<ListView x:Name="SearchListResults"
                  ItemsSource="{x:Bind SearchViewResults.View, Mode=OneWay}"
                  ItemTemplate="{StaticResource RowResultTemplate}"                  
                  SelectedIndex="{x:Bind ViewModel.SelectedIndex, Mode=TwoWay}"
                  SelectedItem="{x:Bind ViewModel.SelectedItem, Mode=TwoWay}"
                  Visibility="{x:Bind ViewModel.ResultsViewVisibility, Mode=TwoWay}"
                  Margin="4,0"
                  Height="{x:Bind ViewModel.SearchListResultsHeight, Mode=TwoWay}"
                  MinWidth="800"
                  SelectionChanged="SearchListResults_SelectionChanged"
                  IsItemClickEnabled="True"
                  ItemClick="SearchListResults_ItemClick"
                  AllowFocusOnInteraction="False">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <ItemsStackPanel AreStickyGroupHeadersEnabled="True" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>

</ListView>

Thank you for your help

phiwhynot
  • 27
  • 4
  • Can you check if your issue is "loading items" or "rendering items"? – Andrew KeepCoding Dec 02 '22 at 23:09
  • Hi Andrew, I think that the problem is in rendering items. The process to search in the database and add objects to the ObservableCollection is fast. I followed the instructions found in https://learn.microsoft.com/en-us/windows/uwp/debug-test-perf/listview-and-gridview-data-optimization (section Random access data virtualization) and got better results. Do you know if there are any rules to follow when displaying a large number of elements. Thanks. – phiwhynot Dec 03 '22 at 15:16
  • Then the RowResultTemplate item template and the ResultItems class might help to see what is the problem. – Andrew KeepCoding Dec 04 '22 at 07:48

1 Answers1

0

The ListView virtualization is bypassed (meaning it renders all its items) when the ListView is in a non-constraining parent.

Make sure your ListView is not in a StackPanel (vertical), ScrollViewer, Grid in that Row that has auto size, or any other Panel (or Control) that offers infinity as the available space in the measure phase.


Now, like you said, loading the data can be fast so you might not need to implement ISupportIncrementalLoading. That's really when you want to add pagination to your data source.

Though, it's always a good idea to measure how long it takes, just to be certain.

Batesias
  • 1,914
  • 1
  • 12
  • 22