Windows Store universal app - ListView oddity

拥有回忆 提交于 2019-12-12 06:55:55

问题


I am developing an universal app and using a ListView to display more than 50000 entries. I am using the following method to load the data:

  1. In the assets folder there's a simple utf-8 txt file with all the items (headwords of a dictionary in alphabetical order just to be precise).
  2. I load the file into an IList with ReadLinesAsync:

    IList<string> lista1 = await FileIO.ReadLinesAsync(listafile1);
    
  3. Finally I set the ItemsSource of the ListView to this IList:

    listView1.ItemsSource = lista1;
    

It seems to be fast and work fine but at the end of the list the items are disappearing after scrolling. I experience this on phones and pc and even in the emulator too. I made a video of it to be more clear.

I already created the same app for android and ios and didn't experience this type of error.

I would appreciate any help

István


回答1:


The solution is to add a VirtualizingStackPanel to ListView in xaml:

        <ListView>
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel/>
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
        </ListView>


来源:https://stackoverflow.com/questions/25039561/windows-store-universal-app-listview-oddity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!