Reference images stored in external dll using wpf

Matt B picture Matt B · Feb 16, 2010 · Viewed 30.1k times · Source

I have a wpf application and a class library(dll) project. In my dll I have an images folder with some .png files set as Resource.

I want to reference and display the image using the wpf main application.

Any ideas? I want to do this in the xaml not the code behind if at all possible.

Ta, Matt.

Answer

b-rad picture b-rad · Feb 16, 2010

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.