如何访问特定的resw资源文件

Tho*_*dre 4 windows-8 windows-runtime

对于C#/ XAML中的Windows 8应用程序,我需要访问特定的ressource文件.在WP7中,我使用了resx文件,现在看来我们需要使用resw文件.它不是语言资源文件.我的文件名为ConfigResources.resw,它只包含一个键:"ConfigFile"和一个值:一个字符串.

如何从我的代码中访问它?我试了一下没有运气:

   var storedConfigFile = Application.Current.Resources["ConfigResources"];
Run Code Online (Sandbox Code Playgroud)

那么如何从我的代码中编辑内部键的值?

谢谢

小智 7

我最近在CodePlex上创建了一个名为ResW File Code Generator的项目,它简化了在windows store app项目中使用代码中的本地化资源.它是一个自定义工具,可以自动生成和更新助手类,类似于完整版.NET中使用的ResX文件


N_A*_*N_A 5

根据这里,您需要使用Windows.ApplicationModel.Resources.ResourceLoaderWindows.ApplicationModel.Resources.Core命名空间提供与resw文件的交互.

它应该看起来像这样:

var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
var text = loader.GetString("Farewell");
Run Code Online (Sandbox Code Playgroud)

或者,如果您正在创建跨平台库,您也可以使用以下方法执行此操作System.Resources.ResourceManager:

虽然System.Resources.ResourceManager类包含在.NET for Windows Store应用程序中,但我们不建议使用它.仅在作为可移植类库项目开发并且以多个平台为目标的库中使用ResourceManager.

这里像这样:

ResourceManager rm = new ResourceManager("Strings", typeof(Example).Assembly);
string timeString = rm.GetString("TimeHeader");
Run Code Online (Sandbox Code Playgroud)