I have a WPF class Library, containing a Folder "Images" that contains an Image. In a WPF application I wont to refer to the image in that Folder using
<Image Name="image" Grid.Row="0" Source="pack://application:,,,/ImageService.dll;Component/Images/image.jpg"/>
The image ist marked as "Ressource" and I also added it to the resources of the class library Project. After some searching I found out, that I have to copy the dll into the exe directory.
During designtime the image is displayed correctly. After launching the executable the source
property of the image is null. No error message and no hints in the output window.
It seems, that the Format of the pack uri is incorrect, so the runtime refers to a wrong place. Is there a way to specify the assembly name relative to the executable, using "....\AssemblyName.dll" or absolute to file systems root.
Unfortunately I cannot assign the imagesource via code, because all the content goes through XAMLWriter - XAMLReader construct from the dll to the executing assembly.
You don't have to copy image to output directory. Make sure you mark the Build Action
as Resource
and set Copy to Output Directory
to false
.
Also, you can skip assembly name in pack URI in case XAML and image resides in same assembly. In case they resides in different assembly, you have to give only assembly name (remove dll from path).
<Image Source="pack://application:,,,/ImageService;Component/Images/image.jpg"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With