Set imagesource of wpf image

不问归期 提交于 2019-12-11 12:43:22

问题


I know that there are a few similiar questions but they don´t help me:

Have got the following code to show a Image in code behind:

BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new `Uri("pack://application:,,,/ApplicationName;component/Images/Klar.JPG");`
logo.EndInit();

The image is in the Images folder at the same level as the bin folder.

What is my mistake?


回答1:


For information about Pack URIs see here. I believe yours should be:

logo.BeginInit();
logo.UriSource = new Uri("pack://application:,,,/Images/Klar.JPG");
logo.EndInit();

which assumes that at the project level you have a folder called Images which contains a jpg called Klar.JPG.



来源:https://stackoverflow.com/questions/10146269/set-imagesource-of-wpf-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!