1

I'm working with Visual Studio 2013 and .NET 4.5.

I had an image linked as follows, with \\, and it was showing up in VS designer view but then not during runtime.

<Image Grid.Column="1" Source="..\\Resources\\MyImage.bmp" Stretch="Uniform"/>

After quite a bit of trying, I got it to work by changing the \\ to / symbols, like so:

<Image Grid.Column="1" Source="../Resources/MyImage.bmp" Stretch="Uniform"/>

I'm just curious as to why the designer was able to find my image with the backslashes while runtime was not, and then why the forward slashes fixed this problem. Anyone know? Thanks

Kevin Marsh
  • 58
  • 1
  • 7

3 Answers3

1

XAML

<Image Source="pack://application:,,,/yournamespace;component/Resources/MyImage.bmp"/>

If I understand your problem correctly. Check your build action on your image.

That's given that your image resides in the Resources folder in your project. If you are wondering about that whole long string there before /Resources/MyImage.bmp, that's for allowing components to be used from other assemblies, and is the safe way of defining images in xaml. "yournamespace" is the namespace of your project.

http://msdn.microsoft.com/en-us/library/aa970069.aspx

Stígandr
  • 2,874
  • 21
  • 36
0

Select the image in your solution explorer and set it's Copy to Output Directory to Copy if Newer and make sure the Build Action is set to Content

Andrew Grinder
  • 585
  • 5
  • 21
-1

For an example: <img src="\website\file_name.jpg" />

This is invalid because a backslash is not allowd in a URL and a backslash must be escaped. So when you go online with your code, all backslashes cannot be read.

The proper way is to write this:

<img src="/website/file_name.jpg" />

Hope it helps!

Anonymous
  • 1,303
  • 4
  • 19
  • 31