我找不到图像不会在我创建的网格中显示的原因
Image img = new Image();
img.Source = new BitmapImage(new Uri(@"C:\logo.bmp", UriKind.Relative));
img.Width = 50;
img.Height = 50;
img.Margin = new Thickness(5, 5, 5, 5);
grid1.Children.Add(img);
答案 0 :(得分:3)
您的图片URI是绝对路径。
你应该写
img.Source = new BitmapImage(new Uri(@"C:\logo.bmp", UriKind.Absolute));
或更好
img.Source = new BitmapImage(new Uri(@"C:\logo.bmp"));