从程序集中加载 ResourceDictionary [英] Load a ResourceDictionary from an assembly

查看:30
本文介绍了从程序集中加载 ResourceDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文件系统的某处有一个程序集,例如C: emp est.dll".在那个程序集中有一个 ResourceDictionary,例如abc.xaml".

I've got an assembly somewhere on the file system, e.g. "C: emp est.dll". In that assembly there's a ResourceDictionary, e.g. "abc.xaml".

我怎样才能得到那个ResourceDictionary?也许有一种使用反射的方法?到目前为止我还没有找到解决方案.

How can i get that ResourceDictionary? Maybe there is a way using Reflections? I didn't find a solution so far.

提前致谢!

只是想补充一点,我想访问词典中的资源,例如一种风格.

Just wanted to add that I want to access the Resources in the Dictionary, e.g. a Style.

推荐答案

我找到了一个更好的解决方案,它适用于 ResourceDictionaries:

I found an even better solution which works with ResourceDictionaries:

Assembly.LoadFrom(@"C:	emp	est.dll");
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri("/test;component/myresource.xaml");

<小时>

好吧,我无法让它与 ResourceDictionaries 一起使用,所以我使用的是旧的资源文件;)对于任何感兴趣的人,我是这样做的:


Well, I couldn't get it to work with ResourceDictionaries, so I'm using good old Resource Files instead ;) For anyone interested, here is how I did it:

Assembly a = Assembly.LoadFile(@"C:	emp	est.dll");
ResourceManager rm = new ResourceManager("NameOfResource", a);
object o = rm.GetObject("xyz");

您可以按照 Ian 的建议使用 Reflector 获取NameOfResource".

You can get "NameOfResource" with Reflector, as Ian suggested.

这篇关于从程序集中加载 ResourceDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆