Set imagesource of wpf image

2019-08-09 14:02发布

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条回答
趁早两清
2楼-- · 2019-08-09 14:26

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.

查看更多
登录 后发表回答