下面的代碼在另一個項目中有效。也在第二個,如果我包括絕對網址。 我在我的項目文件夾中有res文件夾。有什麼不同?圖像相對路徑在一個項目中有效,但不在其他項目中
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"\res\arato.png", UriKind.RelativeOrAbsolute);
myBitmapImage.EndInit();
var img = new Image();
img.Source = myBitmapImage;
img.Margin = new Thickness(0, 0, 0, 0);
canvas.Children.Add(img);
這可能取決於圖像是設置爲「內容」還是「資源」。 – Patrick