在执行 WPF 时更改本地化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14748899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 07:24:01  来源:igfitidea点击:

Change localization at execution WPF

c#.netwpfvisual-studio-2010localization

提问by Sonhja

I have a WPF application that I want it to be two languages. I duplicated my Resources.resxand built my two languages like this:

我有一个 WPF 应用程序,我希望它是两种语言。我复制了我的Resources.resx并构建了我的两种语言,如下所示:

enter image description here

在此处输入图片说明

So when I first load my MainApplicationI do this:

所以当我第一次加载我的MainApplication我这样做:

Properties.Resources.Culture = new CultureInfo("es-ES");

before the

之前

InitializeComponent();

So everything is loaded in the desired language. Now I want to go the obvious step further, and I designed a Select languageon my application:

所以一切都以所需的语言加载。现在我想更进一步,我Select language在我的应用程序上设计了一个:

enter image description here

在此处输入图片说明

Any idea on how to reload the interface for the different languages at execution time?

关于如何在执行时为不同语言重新加载界面的任何想法?

EDIT:

编辑:

I found thislink, and seems to work. But I have a problem. When I try to find the Resources x:keyit launches an error... It says ResourceReferenceKeyNotFoundException. Go hereto check my mistake.

我找到了这个链接,似乎有效。但我有一个问题。当我试图找到Resources x:key它时,它会启动一个错误......它说ResourceReferenceKeyNotFoundException。去这里检查我的错误。

采纳答案by Sonhja

I followed thisinteresting link.

我关注了这个有趣的链接。

回答by Marco Cordeiro

You to change the culture for the UI thread, this should work:

您要更改 UI 线程的文化,这应该有效:

var culture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture);
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));