简体   繁体   English

使用WPF和C#在文化中访问资源文件

[英]Accessing Resource File with Culture in WPF, C#

I am writing an app where the textblocks can display comments in different languages. 我正在编写一个应用程序,其中的文本块可以显示不同语言的注释。 I am attempting to use "Culture" which I really don't understand. 我正在尝试使用我不了解的“文化”。

在此处输入图片说明

I have followed a few videos but still get then same error message: 我已经观看了一些视频,但仍然收到相同的错误消息:

在此处输入图片说明

Here are the namespace I have added: 这是我添加的名称空间:

    using System.Reflection;
    using System.Globalization;
    using System.Resources;

I am just testing the concept out before adding the switch statement: 我只是在添加switch语句之前测试概念:

        CultureInfo cult = CultureInfo.CreateSpecificCulture("en");

        Assembly lingua = Assembly.Load("Bailing Calculator");

        ResourceManager rm = new ResourceManager("Bailing Calculator.Resources.Res", lingua);

        tbkPHDiameter.Text = rm.GetString("phDia", cult);

Am I simply not giving the correct path to the ResourceManager? 我是否只是没有提供通往ResourceManager的正确路径? Thanks for the ensuing onslaught of education! 感谢随之而来的教育冲击!

在此处输入图片说明

Update your code to be seems like: 将您的代码更新为:

  CultureInfo cult = CultureInfo.CreateSpecificCulture("en-US");

  Assembly lingua = Assembly.Load("Bailing Calculator");
  ResourceManager rm = new ResourceManager(string.Format("Bailing_Calculator.Resources.{0}",cult.Name), lingua);
tbkPHDiameter.Text = rm.GetString("phDia");

and update the Resource File name to be your target Culture name: so the file name becomes looks like: en-US 并将“资源文件”名称更新为您的目标区域性名称:这样,该文件名将变为: en-US

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM