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 u开发者_StackOverflowse 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.
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").
精彩评论