THIS POST IS NOW DEPRECATED!
PLEASE FOLLOW THIS NEW GUIDE
One of the things that struck me most when I first started using Xamarin Forms is that, among tens of controls available, there wasn’t a simple image gallery.
At the moment I was working on a project and I really didn’t want to write one by myself so I kept looking hoping to find something similar on Internet. When at the end I found it I was perplexed because it was in the place where I least expected it: in the XamarinLabs project.
What is interesting, and made me think that there wasn’t an ImageGallery control, is the fact that no one talks about it and it isn’t even referenced in the project Wiki!
But if you’re reading this blog, you’re probably here for it so let’s see where it is and how to use it!
USING THE GALLERY
First thing we install via Nuget the package XLabs – Core (check that is version 2.0 or later) in the shared project and in the platform specific projects.
After we’ve added
we can simply use it in this way:
ImageGallery mainImages = new ImageGallery(); mainImages.SetBinding(ImageGallery.ItemsSourceProperty, “images“);
Images is an ObservableCollection of Strings that contains the names of the images, we can insert the file name if the file is in the platform specific projects or simply pass an url of an image and the control will download it for us:
images = new ObservableCollection(); images.Add(“http://blog.xamarin.com/wp-content/uploads/2014/04/monkey.png“); images.Add(“monkey“);