過去兩天裏,這讓我瘋狂,而且發現任何東西似乎都不適用於我的情況,也許有人可以指出我做錯了什麼。從嵌入式資源中創建圖像
我有一個WPF項目,我已經包含相當多的圖像(80ish)。我已將它們添加到項目中,名爲「Images」。他們目前被設置爲嵌入式資源(雖然我也嘗試了常規資源),但似乎沒有任何工作。
我試圖創建和加載類型圖像的ArrayList使用這些文件作爲源,但我失敗相當糟糕。
private void addPicture(string name)
{
string filePath = "pack://MyApp_WPF:,,,/Images/" + name + ".png";
Stream imageStream = assembly.GetManifestResourceStream(filePath);
Image curImage = new Image();
BitmapImage bmpImage = new BitmapImage();
bmpImage.BeginInit();
bmpImage.UriSource = new Uri(filePath, UriKind.Relative);
bmpImage.EndInit();
curImage.Height = 60;
curImage.Stretch = Stretch.Uniform;
curImage.Source = bmpImage;
curImage.Margin = new Thickness(5);
imageList.Add(curImage);
}
這是很容易在我的Windows窗體應用程序做的,但我只是不能想出辦法來使用WPF ...除了資源鏈接任何幫助將是很好的,因爲機會是在這一點上我已經閱讀過它們。
我可以發誓我試過這個,再試一次,這次它工作了,謝謝! –