2

I am creating one image picker in my UWP app wherein I want to show all images from one folder(Picture Library). It is similar to the default Photos App in Windows platform.

What's done till now?

I have used one Grid view & bind it with a list in the code behind file. I have queried the pictures folders and read the images as a stream and added in the list one by one & finally set the list to grid view's source.

Reference: Link

What's the problem?

As I am reading images one by one, I think it will be slow when images in that folder will increase upto say 10k.

Query

Can we do something like pagination in Grid View? As window size is resizable in UWP, at max 30-40 images will be shown at a time, can we load only 30 & when user will scroll down then load 40 more images?

Secondly, can we somehow know how default photos app does this thing?

P.S I have searched a lot but I don't get any way where I can optimise it more. Google, SO etc. but not getting much.

Any help will be appreciated.

hellodear
  • 226
  • 1
  • 2
  • 16
  • Try expanding your search to include wpf instead of uwp. There is a fair amount of discussion out there that can likely be adapted. https://stackoverflow.com/questions/1603605/wpf-paged-collectionviewsource and https://stackoverflow.com/questions/784726/how-can-i-paginate-a-wpf-datagrid – dkackman Jul 16 '17 at 12:28
  • Refer [ListView and GridView UI optimization](https://learn.microsoft.com/en-us/windows/uwp/debug-test-perf/optimize-gridview-and-listview). For pagination refer [Pagination in ListView (UWP)](https://stackoverflow.com/a/44646697/7331395) – Vijay Nirmal Jul 16 '17 at 12:38
  • @dkackman In these links, if I read all the images at once(say in a list), won't those many images will be in app's memory at a time? If yes, then I don't want this. Is there anything provided by framework/library wherein only 30-40 will be in apps memory at a time? I guess that's the way Photos app might be working. I don't know how to query images again if user scroll up again and then down again. Keeping check of the last the image etc. is not a very easy task to do. There must be some mechanism provided by Microsoft in list or grid view or something else. I hope I am able to clarify – hellodear Jul 16 '17 at 15:39

1 Answers1

1

I think it will be slow when images in that folder will increase upto say 10k.

ListView and GridView perform UI virtualization for you by default if you didn't set anything to defeat the UI virtualization. Details please reference "UI virtualization" section of ListView and GridView UI optimization. So that you may not need too much concern about the GridView performance.

can we load only 30 & when user will scroll down then load 40 more images?

To meet this requirements, it seems like data virtualization needed refer to this document:

A method of data virtualization is needed for a data set that is so large that it cannot or should not all be stored in memory at one time. You load an initial portion into memory (from local disk, network, or cloud) and apply UI virtualization to this partial data set. You can later load data incrementally, or from arbitrary points in the master data set (random access), on demand.

You can load data incrementally by data virtualization as you want. Details for how to do please reference the Data virtualization official sample. This sample demostates data virtualization with a custom datasource over the contents of the default pictures folder.

Sunteen Wu
  • 10,509
  • 1
  • 10
  • 21