Reputation: 1
I'm building an app using Xamarin.Forms, and i have a "gallery page". This page consists of many images that are being loaded into the page.
The loading of the images takes quite a while, and when navigating to another page, and afterwards coming back using Navigation.PopAsync and Navigation.PushAsync the entire page needs to be rebuild again (photo's are being loaded all over again).
I've tried caching the page (so not doing Navigation.PushAsync(new GalleryPage()) all the time, but keeping it in a variable, but this makes no difference.
Does anyone know how to cache an entire page, so it does not need to be loaded all over again?
Thank you
Upvotes: 0
Views: 3332
Reputation: 11040
The problem likely lies with the size and number of images you're showing.
I've dealt with the same issue by in two steps:
Create thumbnails - large images take a lot longer to load and if you have a lot of them on the screen they are all small. It may be well worth scaling them down as they come in and storing the thumbnail. A camera-sourced image can be 5-8Mb when a thumbnail may be 20-30K. The large image will also have to be scaled down every time you show it.
Use ListView
to show the images rather than any Grid
, StackLayout
or whatever else you may have. The difference is that ListView is rendered more dynamically, it creates rows only as they are about to be shown, so not all of the images are loaded in memory. Alternatively you can create your own logic that loads and unloads images dynamically. Worst case to watch out for is using a scroll view filled with images - they will likely attempt to render even when they are off-screen
Upvotes: 0
Reputation: 16199
If you keep the Page Object in a variable so you are doing
Page myPage = new Page();
Navigation.PushAsync(myPage);
then later do
Navigation.PushAsync(myPage);
that should certainly keep the page loaded in memory.
Images are generally also cached. So if you are getting them from a URL then they will be cached.
If you are getting them from a database this might be the source of your delay, especially if you ask it to go and refresh the list.
Upvotes: 0