0

I have added Resource Dictionary of a referenced dll in my project. It is an ImageDictionary. Now I want to set source of my image as one of the images in the dictionary. How do I do it? this is how it used to be accessed in the original project.

<Image Source="{StaticResource LoadDrawingImage}"/>

1 Answers1

0

In your window properties, you need to declare this:

xmlns:Image="clr-namespace:[namespace];assembly=[nameofdll]"

and then use like this:

<Image Source="{StaticResource Image:LoadDrawingImage}"/>
Catarina Ferreira
  • 1,824
  • 5
  • 17
  • 26
  • If it worked please mark my answer as accepted :) – Catarina Ferreira Aug 02 '19 at 12:56
  • This won't work, because adding a XAML namespace prefix to a resource key will not magically make the resource from a referenced assembly available in the current project. Actually, adding a namespace prefix to a resource key is invalid XAML syntax. This post should be deleted. – Clemens Aug 03 '19 at 07:54
  • No it's not, because I have a profissional project and sometime we use it like this example. – Catarina Ferreira Aug 05 '19 at 08:03
  • You are certainly confusing things here. `Image:LoadDrawingImage` is not a valid resource key. – Clemens Aug 05 '19 at 08:04
  • That's the example using the data provided in the question. "Image" is the name I gave to the declaration, It can be different. "LoadDrawingImage" is the source of the image that the use gave as an example that he wanted to use. – Catarina Ferreira Aug 05 '19 at 08:08
  • Sure, I can see what you are trying to say. It's still wrong. Try the following. Create a library project with some ResourceDictionary with an entry with a certain key. Create a WPF application project, add a reference to the library, and try to access the external resource by its key via StaticResource as you are showing it here. – Clemens Aug 05 '19 at 08:09