通过使用 resgen.exe,我可以从 txt 文件生成“资源”文件。我可以在 WPF 中使用“资源”文件,但是我不确定如何填充“cshtml”文件中的值。任何帮助,将不胜感激。
问问题
522 次
1 回答
0
设计时.resx
文件被编译成.resources
.NET 程序集中的二进制 blob,然后与ResourceManager
类一起读取。这些 blob 本质上只是键/值字典。
像这样:
ResourceManager res = new ResourceManager("NameOfEmbedded.resources", GetType().GetExecutingAssembly());
String localizedString = res.GetString("resourceKey");
在 Visual Studio 中,将为每个(非本地化).resx
文件创建一个强类型包装器,因此您无需记住每个资源的字符串键,也可以从静态上下文中获取它,因此您需要做的就是:
String localizedString = Resources.ResourceKey;
(假设Resources
是您的.resx
-wrapper 类的名称)
在您的.cshtml
文件中,要呈现本地化文本,请使用相应的@
语法进行呈现:
<p>Hello this next text is localized: @Resources.ResourceKey</p>
这与 WPF 不同,您可以这样做:
xmlns:r="MyNamespace.Properties"
<TextBlock Content="{x:Static r:Resources.ResourceKey}" />
于 2015-11-25T10:15:57.657 回答