WPF 桌面应用程序在 运行 时间获取图像路径

WPF Desktop App Get Path to Image at Run Time

.Net 4.5 WPF 桌面应用程序, 目标是将现有图像添加到 pdfSharp 文档。第一步是获取图像的路径。我的图像位于我项目下的图像文件夹中。我试过:

String myPath = string.Empty;
myPath = System.IO.Directory.GetCurrentDirectory();
myPath = myPath + "\Images\MyImage.png";

myPath ends up being: 
C:\Users\My User Name\Documents\LocalProjects\MyProject\MyProject\bin\Debug\Images\MyImage.png

然后我在 If 语句中使用 File.Exists 检查。失败了。

谢谢!

确保项目中图像文件的 Build Action 设置为 Content,并将 Copy to Output Directory 设置为 Do not copy 以外的值。

否则图像文件(包括其相对路径)将不会被复制到输出目录bin\Debug\