To make the photos look like they are stacked, we need at least 10 of them. Proceed as follows:
- Open MainPage.xaml.cs.
- Add the AddInitalPhotos() method and the InsertPhotoMethod() to the class, as illustrated in the following code block:
private void AddInitialPhotos()
{
for (int i = 0; i < 10; i++)
{
InsertPhoto();
}
}
private void InsertPhoto()
{
var photo = new SwiperControl();
this.MainGrid.Children.Insert(0, photo);
}
First, we create a method called AddInitialPhotos() that will be called upon startup. This method simply calls the InsertPhoto() method 10 times and adds a new SwiperControl to the MainGrid each time. It inserts the control at the first position in the stack, effectively putting it at the bottom of the pile since the collection of controls is rendered from the beginning to the end.