我已经在文件系统上,例如在得到了一个组件的某处“C:\ TEMP \ Test.dll的”。 在该组件有一个ResourceDictionary中,例如“abc.xaml”。

我怎样才能像ResourceDictionary中?也许有使用思考的方式?我没有找到一个解决方案为止。

提前感谢!

编辑:只是想补充一点,我要访问的资源字典,例如伴奏。

有帮助吗?

解决方案 2

修改我发现了一个更好的解决方案,其与ResourceDictionaries作品:

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");

您可以得到 “NameOfResource” 与反射器,作为伊恩建议。

其他提示

您确实需要编写乌里这样的:

Assembly.LoadFrom(@"C:\temp\test.dll");
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(@"pack://application:,,,/test;component/myresource.xaml");

反射副本(鲁兹已交给本结束了)。用它来看看组件和资源在它的命名空间等

然后,在嵌入资源这样的读取;

Assembly 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();
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top