Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 reference the image in a test page like so -

<Page x:Class="Critter.Pages.Test"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Test">
      <Image Source="bug.png"/>
</Page>

Problem is I get a message saying it can't be found or it's build action isn't resource but it DOES exist and it's build action IS resource. If i create a new application and just throw it on a window then it works fine.

Any help would be great.

like image 348
EightyOne Unite Avatar asked Mar 12 '09 14:03

EightyOne Unite


4 Answers

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 
like image 65
Cameron MacFarland Avatar answered Sep 29 '22 18:09

Cameron MacFarland


→ Right click the image file → Click property → Select Build Action to Resource → Clean and Build solution → Run the Solution

You will get the all.

like image 25
sona jha Avatar answered Sep 29 '22 17:09

sona jha


I had the same issue. Cleaning and rebuilding the solution didn't fix it so I restarted visual studio and it did. Here's hoping Visual 2010 fixes this issue and the many others that plauge wpf in Visual 2008.

like image 42
brianstewey Avatar answered Sep 29 '22 18:09

brianstewey


Try starting the path to your image with a "/":

<Image Source="/bug.png"/>
like image 39
Ben Gribaudo Avatar answered Sep 29 '22 18:09

Ben Gribaudo