Reference images stored in external dll using wpf Reference images stored in external dll using wpf wpf wpf

Reference images stored in external dll using wpf


Assuming you reference the class library from the WPF application you can reference and display the image in the WPF application with the following XAML:

<Image Source="/ClassLibraryName;Component/images/myimage.png"/>

The important thing here is "ClassLibraryName" which is the assembly name for your class library. "/images/myimage.png" is the path to your image.

You can find out more about WPF pack URIs here.


This did not work for me:

<Image Source="/ClassLibraryName;Component/images/myimage.png"/>

But this did:

<Image Source="pack://application:,,/ClassLibraryName;Component/images/myimage.png"/>

I also cleaned and rebuilt prior to this, but only after adding this addition bit were the images retrieved.


I was already using below but still didn't work.

<Image Source="/ClassLibraryName;Component/images/myimage.png"/>

I changed the "Build Action" to "Resource" but still didn't work.

Finally, after cleaning the solution and rebuilding all, it worked!!!

Setup: Microsoft Visual Studio Enterprise 2015, Windows 10 Pro, C#