wpf - WPF-图片 'is not part of the project or its Build Action is not set to Resource'

标签 wpf image resources imagesource buildaction

我有一个需要在窗口中显示图像的项目。这是静态图像,我通过“添加>现有项目”添加。它存在于项目的根目录中。

我在测试页中引用了图像,如下所示:

<Page x:Class="Critter.Pages.Test"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Test">
      <Image Source="bug.png"/>
</Page>

问题是我收到一条消息,指出找不到它,或者它的构建 Action 不是资源,但是它确实存在,并且它的构建 Action 是资源。如果我创建一个新的应用程序并将其扔在一个窗口上,那么它将正常工作。

任何帮助都会很棒。

最佳答案

尝试进行完全重建,或删除生成文件,然后生成文件。

Visual Studio并非总能对资源进行更改,因此重新编译可能会很痛苦。

当我遇到相同的问题时,也请尝试使用完整的URI,这对我有帮助。就像是

pack://application:,,,/MyAssembly;component/bug.png

关于wpf - WPF-图片 'is not part of the project or its Build Action is not set to Resource',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/638845/

相关文章:

c# - 棱镜 WPF : How to moq the callback to return IDialogResult. 结果 == Buttonresult.ok

android - "@android:drawable/ic_"与 "@*android:drawable/ic_"

java - Android 中无需本地化的多语言功能,但可通过按钮实现

wpf - 为什么 Flowdocument 的工具提示不显示?

wpf - 实现 INotifyCollectionChanged 接口(interface)

ios - 快速加载 url 图像

python - Pygame:将png图像中的所有白色像素转换为完全透明

iphone - 如何为 iPhone 创建仅资源包

WPF-xaml 计算文本框值的总和

html - 什么在搜索引擎中会被索引得更好 : img tags or background-images with screenreader tags?