Accessing image resources from a loaded assembly
-
28-10-2019 - |
Question
I have a simple plugin architecture for my program that uses an interface to return an ImageSource for an icon. I want each plugin to be able to add an icon/image resource to the assembly and return it from its implemented class.
The problem I'm running into is that when I use my previous trick, which was to instantiate an ImageSourceConverter and pass it a pack uri, doesn't work with loaded assemblies because the converter loads the resource from the main assembly.
public static ImageSource FromResourcePath( string path ) {
return (ImageSource)new ImageSourceConverter().ConvertFrom( "pack://application:,,,/" + path.TrimStart( '/' ) );
}
Is there any (hopefully straightforward) way to get an ImageSource from an assembly resource (stored as a WPF "Resource" content type) from a loaded assembly? I'd like to avoid using streams if at all possible.
Solution
"pack://application:,,,/<PutHereAssemblyName>;component/" + path.TrimStart('/')
Hope this helps :)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow