I am actually solving the issue with stack panel and images I would like to show in it.
What my approach was: Because of just about 50 pictures to be shown , I just get ti image , make a thumbnail from it , and place that one by one to the stackpanel on left side of my program. (As bitmap) User is able to click on image and do the action with a image. Required amount was about 50 images.
New state: New state is that the required amount of images is about 500 so 10 times more. The problem is even my thumbnail is too small when I am adding it like :
foreach image in list do :
- create thumbnail
- add on click or and on touch event to that thumbnail
- add that thumbnail to the stack panel
I saw somewhere was used a picture box , not sure if that will help me.
I am thinking about creating lists of pictures links (50 in every ) and put for instance first in a scroll bar and when scrollbar reaches the bottom, load next and when the top reaches load previous list.
The problem is I am reaching with ~ 175 images the maximum of process memory. I am waiting for garbage collector to do its job after every cycle.
Maybe my approach is not good or should be different so this is why I am asking which approach use in order to solve this problem you suggest.
The source of the photos is simply folder of thumbnails of size 150x150 .
The images are added one by one in certain period of time ( one foto every one second or so )
Thank you
An example of implementation.
The collection can contain a string or an Url with a path to the image. In this case, the image will be created only when it is shown in the Window.
You can also set an instance of ImageSource (or rather classes derived from it). In this case, the image will be immediately loaded into memory.
Also set the property for specifying the selected image.
In the Element Template, specify the Image with the binding to the element and the thumbnail sizes you need.
Assign the selected item to the property for the selected image.
The ListBox has a VirtualizingStackPanel built in by default, so you don't need to take any additional steps to limit using memory.
In the viewing region, set the Image with a binding to the property for the selected image.
Тестирование.
More than 1200 images in JPG and PNG formats are pre-recorded in the folder "C:\150x150".
The ViewModel gets a list of files in this folder and creates a string array with their paths. The time for this operation is also recorded.
On the left side is a ListBox showing images in size 150x150 for all files.
Results: the time of obtaining the paths is 12-14 ms, the images are displayed instantly.
There are NO LAGS AT ALL when scrolling.
The same was verified for image files of arbitrary format from 128x128 to 4200x2800.
The result is the same.