Search code examples
c#wpfimagedllpng

Reference images stored in external dll using wpf


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.


Solution

  • 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.