从Silverlight类库访问应用程序中的resx [英] Access resx in application from Silverlight class library

查看:124
本文介绍了从Silverlight类库访问应用程序中的resx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用以下代码访问Silverlight中的资源文件:

Resource files in Silverlight can be accessed using the code below:

ResourceManager rm = new ResourceManager("MyLibraryNamespace.MyFolder.MyResources", Assembly.GetExecutingAssembly());

但是,在我的应用程序中,这段代码并不在应用程序本身中,而是在Silverlight类库中,并且该应用程序已经引用了它;将名称空间更改为"MyAppNamespace"只会产生错误.

However in my application this piece of code is not in the application itself, but in a Silverlight class library and the app has reference to it; changing the namespace to the "MyAppNamespace" just generates error.

如何从Silverlight类库访问xap文件中的资源?

How can I reach the resources in the xap file from the Silverlight class library?

推荐答案

为了实现我想要的目的,我必须执行以下操作:

In order to achieve what I wanted I had to do the following:

var assembly = Application.Current.GetType().Assembly;

然后,我可以使用以下资源创建ResourceManager:

And after that I can create ResourceManager with the resources like this:

var rm = new System.Resources.ResourceManager(name, assembly);

其中name是我第一篇文章的路径.

where name is the path from my first post.

这篇关于从Silverlight类库访问应用程序中的resx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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