有人可以显示针对每个语言环境使用.resx文件来国际化两种不同语言的WPF应用程序的最佳解决方案吗? 我还希望能够即时切换语言环境并在运行时更改xaml文本组件的内容
答案 0 :(得分:1)
这里是一个链接,逐步说明了您的需求。 参考: http://www.thebestcsharpprogrammerintheworld.com/2017/07/26/localizing-a-wpf-program-using-c/
XAML:
<Label Content="{x:Static properties:Resources.LabelAddress}" Height="28" HorizontalAlignment="Left" Margin="35,103,0,0" Name="labelAddress" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="119,26,0,0" Name="textBoxFName" VerticalAlignment="Top" Width="152" />
后面的代码:
using System.Globalization;
using System.Configuration;
Properties.Resources.Culture = new CultureInfo(ConfigurationManager.AppSettings["Culture"]);
//To change the locale in runtime you need to set
public static void SetLanguage(string locale)
{
if (string.IsNullOrEmpty(locale)) locale = "en-US";
Properties.Resources.Culture= new System.Globalization.CultureInfo(locale);
}
AppConfig.cs:
<appSettings>
<add key="Culture" value="zh-CN" />
</appSettings>