How to set a WPF image source without writing the assembly name? How to set a WPF image source without writing the assembly name? wpf wpf

How to set a WPF image source without writing the assembly name?


You can use relative paths:

(1). Relative to the project:

<Image Source="/Untitled.png".../>

(2). Relative to the XAML file path where this element is defined:

<Image Source="Untitled.png".../>

But, if the image is located in an external assembly then you have to specify the assembly name, otherwise there is no way WPF can find it.


I've written an image manager which is a custom markup extension, which has registered assemblies, and is just passed the image name, and it locates the image from the list of registered assemblies. You could do something similar if you don't like the idea of assembly names being in the XAML markup for external assemblies.

http://www.switchonthecode.com/tutorials/wpf-tutorial-fun-with-markup-extensions is a nice starting point.