I wanted to make a function that populates a Grid in WPF with pictures. So I did that:
private void setCellImage(Grid g, Image img, int column, int row)
{
Grid.SetColumn(img, column);
Grid.SetRow(img, row);
if (!g.Children.Contains(img))
g.Children.Add(img);
g.UpdateLayout();
}
And was using it by calling in that way:
for (int i = 0; i < 15; i++)
for(int j=0; j<15; j++)
setCellImage(gameMap,background, i, j);
But it wasn't working. it populated a grid only in cell 14,14 leaving all other cells blank.
I thought that it may be my mistake that I should use another instances of Image but it wasn't that:
private void setCellImage(Grid g, Image img, int column, int row)
{
Image _img = new Image();
_img = img;
Grid.SetColumn(_img, column);
Grid.SetRow(_img, row);
if (!g.Children.Contains(_img))
g.Children.Add(_img);
g.UpdateLayout();
}
This thing is still not working.