0

I need some help with imagebrush it only works with absolute directories for example

<ImageBrush x:Name="bgimage" ImageSource="C:\Users\user\Desktop\MediaSampleWPF\MediaSampleWPF\obj\Debug\image.png" Stretch="Fill"/>

works fine but this

<ImageBrush x:Name="bgimage" ImageSource="image.png" Stretch="Fill"/>

gives me this error - if I replace image.png with notexist.png it gives me an error before compilation, but if I gut image.png it does not, meaning that the image actually exists

IOException: Cannot locate resource 'image.png'

the image is in every single directory of the solution , like, literally, i opened every folder in the project solution and i put image.png, but it still say that the image does not exist can someone help me?

1 Answers1

0

I am guessing you are trying to do this in XAML? If so, have you tried adding the image to your project as a resource? My example is using an image on a button, but it will work the same for a brush. In the project, or in a project subfolder "Add Existing Item" via right-click with the mouse or from the Project menu.

Then you can use a relative path to the resource in the project.

XAML snippet

enter image description here

In the .csproj file it ends up as an XML entry that looks like this:

<ItemGroup>
  <Resource Include="Images\IO-64-black.png" />
</ItemGroup>