我在文件系统上的某个地方有一个程序集,例如 "C:\temp\test.dll"。
在这个程序集中有一个 ResourceDictionary,例如 "abc.xaml"。
如何获取该 ResourceDictionary?也许可以使用 Reflections 的方法吗?目前我还没有找到解决方法。
先谢谢您了!
编辑:补充说明我想要访问字典中的资源,例如一个样式。
我在文件系统上的某个地方有一个程序集,例如 "C:\temp\test.dll"。
在这个程序集中有一个 ResourceDictionary,例如 "abc.xaml"。
如何获取该 ResourceDictionary?也许可以使用 Reflections 的方法吗?目前我还没有找到解决方法。
先谢谢您了!
编辑:补充说明我想要访问字典中的资源,例如一个样式。
你实际上需要像这样编写Uri:
Assembly.LoadFrom(@"C:\temp\test.dll");
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(@"pack://application:,,,/test;component/myresource.xaml");
编辑:我找到了一种更好的解决方案,它可以与资源字典一起使用:
Assembly.LoadFrom(@"C:\temp\test.dll");
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri("/test;component/myresource.xaml");
我无法让ResourceDictionaries正常工作,所以我改用传统的资源文件;)
对于任何有兴趣的人,这是我做的:
Assembly a = Assembly.LoadFile(@"C:\temp\test.dll");
ResourceManager rm = new ResourceManager("NameOfResource", a);
object o = rm.GetObject("xyz");
UriKind
,如果你使用相对路径,应该提供 UriKind.Relative
。 - ANewGuyInTownAssembly asm = System.Reflection.Assembly.GetExecutingAssembly();
using (System.IO.Stream s = asm.GetManifestResourceStream(<yourname>)
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(s))
{
string xml = reader.ReadToEnd();
}
}