c# - 文件不是项目的一部分或生成操作未设置为 "Resource"

标签 c# wpf resources

我得到了错误

The file /DocomGUI;component/Resources/logo.jpg is not part of the project or its 'Build Action' property is not set to 'Resource'.

但是 logo.jpg 文件绝对是项目的一部分,Build Actions 也设置为“Resource”。

Project structure File properties

它位于项目根目录的 /Resources/ 文件夹中,也位于同名的 Resources.resx 文件中。

Resources file

我尝试重建解决方案,清理它,但仍然弹出错误。还有什么可能出错导致找不到文件?

代码:

<Window x:Class="DocomGUI.AboutWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="AboutWindow" Height="180" Width="220" Background="LightGray" MinWidth="220" MinHeight="115" MaxWidth="220" MaxHeight="115">
    <Grid>
        <Label Margin="0,66,24,48">DocomGUI</Label>
        <Label Height="30" Margin="12,0,12,12" Name="VersionLabel" VerticalAlignment="Bottom"></Label>
        <Image Margin="12,12,12,0" Stretch="Fill" Height="48" VerticalAlignment="Top" Source="/DocomGUI;component/Resources/logo.jpg" />
    </Grid>
</Window>

最佳答案

我以前也遇到过这种情况,实际上只需重新启动 visual studio 即可自行修复。我不太确定为什么。

关于c# - 文件不是项目的一部分或生成操作未设置为 "Resource",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11632026/

相关文章:

c# - 如何根据.NET Framework 版本定义离开代码?

c# - 使用在 "Parent"ViewModel (MVVM) 中声明的命令

c# - 在选择更改事件上禁用事件冒泡 - WPF

javascript - 除了使用JS之外,如何清除文本框

c# - ASP.Net MVC 路由映射

c# - 在 UWP 中使用 MergedDictionaries 嵌套 ResourceDictionaries

c# - 在页面之间传递数据 C# WPF

delphi - 无法连接定义的字符串和图像文件路径中的文本

Android ImageButton setImageResource 来自变量

wpf - 使用样式设置WPF控件背景图像?