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

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

问题描述

我在文件系统上,例如有一个集会的地方C:\\ TEMP \\ Test.dll的。
在该装配有一个ResourceDictionary中,例如abc.xaml。

I've got an assembly somewhere on the file system, e.g. "C:\temp\test.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:\temp\test.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:\temp\test.dll");
ResourceManager rm = new ResourceManager("NameOfResource", a);
object o = rm.GetObject("xyz");

您可以得到NameOfResource与反射,伊恩建议。

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

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

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