我有两个相似的代码来填充图像数组。这个有效:
for (int i = 0; i < num_of_slides; i++) //populate an array to hold original size images for each slide
{
var fileName = @dir + (i + 1) + ".png";
var bitmap = new BitmapImage(new Uri(fileName)); //{ /*.. more bitmap image options if you like .. */ };
Image image = new Image() { Source = bitmap /*.. more image options ..*/ };
image_array[i] = image;
}
但是这个:
for (int i = 0; i < 4; i++) //populate an array to hold original size images for each slide
{
var fileName = @"/Images/"+i+".jpg";
var bitmap = new BitmapImage(new Uri(fileName, UriKind.Relative)); //{ /*.. more bitmap image options if you like .. */ };
Image studio_image = new Image() { Source = bitmap /*.. more image options ..*/ };
custom_studio_images[i] = studio_image;
}
在custom_studio_images[i] = studio_image;
说它没有设置为对象的实例。我将不胜感激任何帮助或建议。