0

I wish I could change the path of the source image, to match the folder of my project.

Current code

img1.Source = new BitmapImage(new Uri("C:/Users/User/Documents/Visual Studio 2015/Projects/Referenciel/WpfApplication1/Resources/bateleur.gif"));

What I am trying to set up

img1.Source = new BitmapImage(new Uri(@"\Referenciel\WpfApplication1\Resources\bateleur.gif"));

But I have an error : Invalid URI - Unable to determine the URI format.

Thank you

slugster
  • 49,403
  • 14
  • 95
  • 145
Manudog
  • 159
  • 10
  • Take a look at http://stackoverflow.com/questions/13342123/how-to-get-relative-path-of-a-file-in-visual-studio. – DWright Aug 15 '16 at 02:44

2 Answers2

0

Try this:

img1.Source = new BitmapImage(new Uri(@"..\Resources\bateleur.gif", UriKind.Relative));

EDIT:

In the image Properties window set Build Action to Resource.

Cyferka
  • 92
  • 1
  • 6
-1

Don't start your path with a \.

Edit

This one should solve your question.

Original answer.

img1.Source = new BitmapImage(new Uri(@"\Referenciel\WpfApplication1\Resources\bateleur.gif", UriKind.Relative));
Community
  • 1
  • 1
Jai
  • 8,165
  • 2
  • 21
  • 52