0

I have a WPF application where I added the images as resources to the project (not from project settings, like how the 2nd answer does it here), so they are under a folder. I use them like this in xaml:

<Image Width="32" Height="32" Source="/Images/Effect.png" />

When I build this app, only the dependent dlls and the app itself is put into the Debug/Release folder. The Icons that reside inside the project and the actual folders and files are inside the project's folder. Those aren't copied into Debug/Release.

I am able to run this application from anywhere, and the images work, so it must be turning the relative paths to hard coded paths?

If that's the case, how am I gonna be able to distribute those Image files to other machines?

I want to be able to always have the Images relative to the app, both in reference and on disk.

Is this the best way or is there a better way? In the end, I want to easily distribute these images and the app to other machines.

Community
  • 1
  • 1
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
  • Aren't the images compiled right into the binary? – BoltClock Apr 27 '11 at 17:55
  • It does? How can I verify this? You might be right though, I renamed the Images folder and the application still worked. But if the images are compiled into the exe, then why am I getting this issue? http://stackoverflow.com/questions/5807310/images-in-a-wpf-window-throw-exception-when-launched-via-reflection/5807363 – Joan Venge Apr 27 '11 at 17:57

1 Answers1

3

The images are getting compiled into the assemblies as resources. They are not referenced from their original location on your disk.

When you specify your Image.Source like that, WPF looks for the appropriate image in the current assembly. You can also reference images (as well as other resources) that reside in referenced assemblies. Here is some detailed explanation about the resource URI format in WPF (called "Pack URI").

Fyodor Soikin
  • 78,590
  • 9
  • 125
  • 172