这是我的代码:
BitmapImage bitmapImage;
if (ImagesInBase64[imageName.ToString()].Equals(string.Empty))
{
bitmapImage = new BitmapImage(new Uri(string.Format("{0}\\Images\\Application\\{1}.png", AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar), imageName), UriKind.Relative));
}
else
{
bitmapImage = ImageProcessor.Base64StringToBitmap(ImagesInBase64[imageName.ToString()]);
ImageProcessor.SaveMyImage(ImagesInBase64[imageName.ToString()], imageName);
}
var image = new Image();
image.Source = bitmapImage;
image.SetValue(Grid.RowProperty, row);
image.SetValue(Grid.ColumnProperty, column);
image.Margin = new Thickness(10, 5, 10, 5);
grid.Children.Add(image);
当代码进入else时,一切都按预期工作。我可以将图像看作网格的一部分。但是,当代码进入if部分时,即使bitmapImage是有效的BitmapImage,图像也不会显示在网格中。什么事情发生了?