将图像添加到网格 - WPF

时间:2013-05-30 18:22:39

标签: c# image grid

如果我在循环中创建了所有图像,我想知道如何将图像设置为“grid_Main”(参见代码)。

代码:

private void MoleImageMaker()
{
    NumofImages = TUtils.GetIniInt(Moleini, "NumPictures", "pictures", 8);
    String MoleImageFunction = TUtils.GetIniFileString(Moleini, "ImagePath", "PictureFile", Root + "mole2.png");

    for (int i = 0; i < NumofImages; i++)
    {
        Image mole = new Image();
        mole.Source = new BitmapImage(new Uri(MoleImageFunction));
        mole.Name = "Mole" + i;
    }
}

1 个答案:

答案 0 :(得分:2)

像这样的东西

for (int i = 0; i < NumofImages; i++)
{
  Image mole = new Image();
  mole.Source = new BitmapImage(new Uri(MoleImageFunction));
  mole.Name = "Mole" + i;  
  Grid.SetColumn(mole, i);
  grid_Main.Children.Add(mole);
}