Wpf 如何在不同语言资源文件之间动态切换?
在我的wpf项目中,我添加了两个资源文件:Wpf 如何在不同语言资源文件之间动态切换?,wpf,localization,Wpf,Localization,在我的wpf项目中,我添加了两个资源文件: Resources\English.resx and Resources\German.resx 在MainWindow.xml中,我尝试从资源文件中查找值: <Window x:Uid="Window_1" x:Class="LocalizationInvestigate.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Resources\English.resx and Resources\German.resx
在MainWindow.xml中,我尝试从资源文件中查找值:
<Window x:Uid="Window_1" x:Class="LocalizationInvestigate.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Resources="clr-namespace:LocalizationInvestigate.Resources"
Title="MainWindow" Height="350" Width="525">
<Grid x:Uid="Grid_1">
<Label x:Uid="Label_1" Content="{x:Static Resources:English.LabelHello}"></Label>
</Grid>
</Window>
对于英语来说,这种方式非常有效。但是,基于本地语言,如何使用:Resource:derman.LabelHello?自动切换到德语通常,您会创建名称中带有标准区域性字符串的资源文件。例如 Strings.en.resx
Strings.en-US.resx
Strings.de-de.resx
Strings.de AU.resx
资源管理器将根据
线程.CurrentUICulture
切换区域性。我认为这是一篇关于它的好文章。本地化还具有回退行为,因此未知的区域性将使用en
资源进行应答
XAML中的用法是
<Label Content="{x:Static Resources:Strings.LabelHello}" />
谢谢你的回答。我创建了另一个资源:fr CA,但当我这样设置它时:Thread.CurrentThread.CurrentUICulture=new System.Globalization.CultureInfo(“fr CA”);无法切换到fr CA语言文件,因为我不知道您更改了什么,等等。很难判断,出了什么问题……您不应该更改CurrentUICulture
。您需要将Strings.Culture
设置为要使用的区域性。