且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在我的WPF应用程序,图像加载我PNG标志显示在设计时,但在运行时不

更新时间:2023-11-10 21:37:34

在指定图像的URI在XAML中,它通常是不necesary写完整的URI。除了由RV1987所示的全包的URI,你也应该能写出这样的:

When you specify the image URI in XAML, it is usually not necesary to write the full URI. Besides the full Pack URI shown by RV1987, you should also be able to write this:

<Image ... Source="images/ServerMainLogo.png"/>

然而,你必须确保图像文件位于您的Visual Studio项目命名为图像文件夹中,它的生成设置为资源行动,如图的这个答案

另外,您可以设置的生成操作内容复制到
输出目录
复制总是复制如果新。在这种情况下,图像不嵌入作为资源到程序的装配,但简单地复制到相对于该可执行文件的目录。

Alternatively you could set the Build Action to Content and Copy To Output Directory to Copy always or Copy if newer. In this case the image is not embedded as resource into your program's assembly, but simply copied to a directory relative to the executable file.

(相对)图像URI在XAML将在两种情况下工作。

The (relative) image URI in XAML would work in both cases.