簡體   English   中英

文件不是項目的一部分,或者“構建操作”未設置為“資源”

[英]File is not part of the project or Build Action not set to “Resource”

我得到錯誤

/DocomGUI;component/Resources/logo.jpg文件不是項目的一部分,或者其“ Build Action”屬性未設置為“ Resource”。

但是logo.jpg文件絕對是項目的一部分,並且Build Actions也設置為“ Resource”。

項目結構文件屬性

它位於項目根目錄的/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>

這以前發生在我身上,實際上只是通過重新啟動Visual Studio來修復自身。 我不太確定為什么。

如果在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}" />    

我建議這樣做是因為我曾經遇到過類似的問題,並且此變通辦法已為我解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM