My question is: Am I reading MSDN wrong OR is MSDN wrong? I am trying to reference an image Resource via relative URI.
The MSDN page titled
The answer is this: The leading slash in a relative path always resolves to the main assembly, NOT the assembly that the markup is in.
To make it work the way that MSDN states, I would have to store all icons in an "Icons/" folder in the main assembly, instead of in the custom control dll.
If you choose to store the resources in the dll assembly in an "Icons/" folder, you must reference them with a path relative to the markup you're working on (i.e. "../Icons/folder.png
") OR you must qualify the path with the assembly name (i.e. "/AssemblyName;component/Icons/folder.png
")
Just replace < ApplicationName> with the name of your application and this should work
Source="/<ApplicationName>;component/Icons/folder.png"
The reason, when running as a separate assembly, that your Relative Pack URI must begin with ../
or no leading backslash is because of how relative URIs are used, from MSDN (emphasis mine):
Absolute vs. Relative Pack URIs
...
If a leading backslash is used, however, the relative pack URI reference is then considered relative to the root of the application.
Therefore if you'd like the images to remain relative to your referenced assembly, simply omit the leading slash or use ../
if in a sub-folder.
See the image below for an example of how this looks at runtime: