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

后端 未结 10 1885
有刺的猬
有刺的猬 2020-12-29 20:26

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 re

相关标签:
10条回答
  • 2020-12-29 20:49

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

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

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

    pack://application:,,,/MyAssembly;component/bug.png
    
    0 讨论(0)
  • 2020-12-29 20:49

    I had the same error message but my issues was a simple NOOB mistake.

    When I added my .ico files to "My Project / Resources", VS made a sub folder named Resources and I was trying to use;

    <Window Icon="icons1.ico">
    

    when I should have been using;

    <Window Icon="Resources/icons1.ico">
    

    ... don't judge, I started using WPF 1 week ago :)

    0 讨论(0)
  • 2020-12-29 20:50

    There is a solution to your question

    <Image Source="/WpfApplication4;component/images/sky.jpg" />
    

    "component" is not a folder!

    0 讨论(0)
  • 2020-12-29 20:50

    I faced the exact same issue but restarting VS2008 or cleaning and rebuilding the project did not work for me. In the end, the below steps did the trick.

    • In Windows Explorer copy the Image into your project resource folder. Example: MyProject\Resources\
    • From within Visual Studio right click on the Resources and select "Add > Existing item" and select the image which you have just copied in
    • From within the form XAML set the image source as: "Source="Resources/MyImage.ico" (my image was saved as icon (.ico) file, but this approach should work for any image type

    Hope this helps someone

    0 讨论(0)
提交回复
热议问题