I have a problem. I have a TabbedPage, with page1 and page2. On page2 is a Grid with a few images. When I click on the Image, I add the image to a Collection, so I use a OnChange on page1. On page1 I want to add the image that is new to the StackLayout on that page.
Here is my code so far: This is the page2 code:
private void LoadTemplateList()
{
string[] imageArray = { "Good_Question.png", "Excuse_Me.png"};
int imageIndex = 0;
for (var i = 0; i <= TemplateGrid.RowDefinitions.Count; i++)
{
if (i == 2)
{
for (var j = 0; j < TemplateGrid.ColumnDefinitions.Count; j++)
{
if (j == 1 || j == 3)
{
Image image = new Image { Source = imageArray[imageIndex], VerticalOptions = LayoutOptions.StartAndExpand };
var SelectImage = new TapGestureRecognizer();
SelectImage.Tapped += AddImageToCollection(image);
image.GestureRecognizers.Add(SelectImage);
TemplateGrid.Children.Add(image,j,i);
imageIndex++;
}
}
}
}
}
private EventHandler AddImageToCollection(Image image)
{
HomePage.SelectedImageCollection.Add(image);
return null;
}
But the GestureRecognizer doesn't seem to work when I click the image...
What am I doing wrong?
ObservableCollection
has anAdd
method, did you try it? It also has a constructor that allows initialize its contents with the contents of anotherObservableCollection
– Tonyprivate void AddImageToCollection(Image image)
– Tony