I have image in project added as resource, if I try to add it to my WPF project it always end up with
Error 1 The file images\background.png is not part of the project or its 'Build Action' property is not set to 'Resource'. C:\Users\Martinek\Documents\My\Learning.Dot.Net\WPF.8\WPF.8\Window1.xaml 21 47 WPF.8
I also tried to reference full path “file:///” etc. and same results even when image is added as resource
See also XAML code with results
<ImageBrush AlignmentX="Left" ImageSource="images/background.png" Stretch="Fill" />
Attaching image:
https://i.stack.imgur.com/bSjwi.png
I noticed that you have the
Copy to Output Directoryoption set to “Do Not Copy.”Try changing it to either “Copy Always” or “Copy if newer” and see if that helps.
Update
I just wrote a quick sample app to try to figure this out. It seems to work properly, so I’ll post my code here hoping that it’ll help.
In the code-behind, I added some tracing code to see where the
ImageBrushthinks itsImageSourceis.When running that in Debug mode, you should see a line written to the Output window (as well as to the *.trace.log file) with the URI where it thinks the image is located.
I ran it with the image in an images folder off the root of my solution. I tried it with the image set as “Content” (with “Copy if newer”) as well as “Resource” (with do not copy), and it ran successfully both times.
Hope this points you in the right direction.