UWP在Class Library 类库项目中读取.resw文件中的内容
为了今后方便调用通常需要将公共方法编译成dll等类库形式,下面方法是在类库项目中读取Strings.resw资源文件的内容(可用于实现多语言组件):
Windows.ApplicationModel.Resources.Core.ResourceContext resourceContext = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse(); Windows.ApplicationModel.Resources.Core.ResourceMap resourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("【不带路径的文件名不带扩展名】"); // Here you load the resource you need var resourceValue = resourceMap.GetValue("【字段名如图Message】", resourceContext); string valueString = resourceValue.ValueAsString;