在应用程序中为图像源设置URI到根目录

met*_*lah 1 c# wpf

如何在WPF应用程序中将图像源的URI设置为根目录(即与exe相同的文件夹)?

var myImage = new Image();
myImage.Source = new BitmapImage(new Uri("pack://application:,,,/AssemblyName;component/speedline.png", UriKind.Absolute));
Run Code Online (Sandbox Code Playgroud)

我已经尝试了上述内容并继续收到以下错误消息:

mscorlib.dll中发生了未处理的"System.IO.FileNotFoundException"类型异常.附加信息:无法加载文件或程序集"AssemblyName,Culture = neutral"或其依赖项之一.该系统找不到指定的文件.

我显然做了一些非常错误的事情,但可以保证可以C:\Users\Admin\Documents\Visual Studio 2013\Projects\Speedy\Speedy\bin\Debug在与我的exe文件相同的文件夹中找到png 文件,但是如何引用它呢?

MAN*_*OPI 5

在名为component的解决方案资源管理器下创建一个新文件夹,并在其下添加现有图像.现在尝试使用相对路径.

myImage = new BitmapImage(new Uri("/component/speedline.png", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)