WPF - 图像'不是项目的一部分或其构建操作未设置为资源' [英] WPF - Image 'is not part of the project or its Build Action is not set to Resource'

查看:236
本文介绍了WPF - 图像'不是项目的一部分或其构建操作未设置为资源'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a project which requires an image in the window. This is a static image and i added through 'Add>Existing Item'. It exists in the root of the project.

我在测试页面中引用图像,如此 -

I reference the image in a test page like so -

<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>

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

Problem is I get a message saying it can't be found or it's build action isn't resource but it DOES exist and it's build action IS resource. If i create a new application and just throw it on a window then it works fine.

任何帮助都会很棒。

推荐答案

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

Try doing a full rebuild, or delete the build files and then build the file.

Visual Studio不会t总是接受对资源的更改,重新编译它会很痛苦。

Visual Studio doesn't always pick up changes to resources, and it can be a pain to get it recompile.

还尝试使用完整的URI,因为当我遇到同样的问题时,这会帮助我。类似

Also try using a full URI as that helped me when I had the same problem. Something like

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

这篇关于WPF - 图像'不是项目的一部分或其构建操作未设置为资源'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆