Why program crashes by adding a lot of images to listview?

后端 未结 2 909
庸人自扰
庸人自扰 2021-01-17 08:44

This is my XAML:

         


        
2条回答
  •  不思量自难忘°
    2021-01-17 09:07

    After some long time I found several solutions of this problem. There are easy ways, as for me, and some harder ways. The easiest way, I think: In my code in the question we need to change code below:

    
        
    
    

    "WrapPanel" replace on "VirtualizingStackPanel". In this way program will work as user @mkArtak suggested:

    Also, you should use some kind of virtualization when showing the image thumbnails in the bottom area, as you don't want to load all the images at once. Feels like pretty common scenario to have a control for that available somewhere, which you can reuse. The idea is to load only the images which are visible +2 maybe from each side. Then, load anything else, as the user scrolls.

    As I understood this is the virtualization. Of course, you can tune how virtualization must be. You can find info about that in internet.

    And a little more harder way: using async\await what suggested user @Clemens

    You could have a view model that loads thumbnail image files asynchronously, and also limits their size by setting the DecodePixelWidth or DecodePixelHeight property.

    Also, we can use both of this ways and it will be the best way, I think.

    Thanks very much everyone for your help in finding the solution of this problem.

提交回复
热议问题