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

后端 未结 10 1883
有刺的猬
有刺的猬 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: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

提交回复
热议问题