【问题标题】:File is not part of the project or Build Action not set to "Resource"文件不是项目的一部分或构建操作未设置为“资源”
【发布时间】:2012-07-24 13:34:46
【问题描述】:

我得到了错误

文件 /DocomGUI;component/Resources/logo.jpg 不是项目的一部分,或其“构建操作”属性未设置为“资源”。

logo.jpg 文件肯定是项目的一部分,并且 Build Actions 也设置为“资源”。

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

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

代码:

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

【问题讨论】:

  • 可能是删除公司名称的空白。 ;)
  • 完全正确 ;-) 很抱歉 - 在你受到诱惑之前:不,文件名在任何地方都是正确的^^
  • @FlorianPeschka:还考虑套管等?你可以让它工作,比如说文件夹图标吗?
  • 是的。所有其他图像都可以在同一窗口中正常使用。
  • 我曾经通过简单地重新启动 Visual Studio 解决了这个问题,如果一切看起来都正确,那么值得一试。

标签: c# wpf resources


【解决方案1】:

我以前也遇到过这种情况,实际上只需重新启动 Visual Studio 即可自行解决。我不太清楚为什么。

【讨论】:

    【解决方案2】:

    如果你像这样在 window.resources 中声明它会发生什么:

    <BitmapImage x:Key="logo" UriSource="/Resources/logo.jpg" />
    

    并像这样使用它?

    <Image Margin="12,12,12,0" Stretch="Fill" Height="48" VerticalAlignment="Top" Source="{StaticResource logo}" />    
    

    我提出这个建议是因为我曾经遇到过类似的问题,而这个解决方法对我来说很有效。

    【讨论】:

      猜你喜欢
      • 2015-09-08
      • 1970-01-01
      • 2015-07-05
      • 2013-04-25
      • 2018-02-26
      • 2013-11-09
      • 1970-01-01
      • 2012-12-13
      相关资源
      最近更新 更多