How to set WPF image source without writing assembly name?

Typically a WPF image source is similar to

WpfApplication1;component/Untitled.png 

But what if I need to rename an assembly? Do I need to change all image sources?

+6
image path wpf assemblies
source share
2 answers

You can use relative paths:

(one). Regarding the project:

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

(2). Regarding the path of the XAML file where this element is defined:

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

But if the image is in an external assembly, you need to specify the name of the assembly, otherwise WPF will not be able to find it.

+8
source share

I wrote an image manager, which is a custom markup extension that has registered assemblies and just passed the image name, and it finds an image from the list of registered assemblies. You can do something similar if you don't like the idea of ​​assembly names found in the XAML markup for external assemblies.

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

0
source share

All Articles