我有一个很常见的问题.在WPF应用程序中进行本地化的最佳方法是什么.好吧,我在SO和Binged中搜索了很多.但我找不到任何非常简单和优雅的指针.
假设我必须在UI中显示如下内容:
英语:Orgnanization - Beoing
法语:Organizzazione - Beoing
<StackPanel Orientation="Horizontal">
<TextBlock Text="Organization -"></TextBlock>
<TextBlock Text="{Binding Path=OrganizationName}">
</TextBlock>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
基本上,我需要将本地化文本分配给Organization Label TextBlock.我应该将连字符与"组织 - "分开并将其放在单独的标签中吗?
我怎么做?
我正在尝试更改我的WPF应用在单击事件中使用的语言,但它不会更改.
private void menuItemGerman_Click(object sender, RoutedEventArgs e)
{
Settings.Default.Culture = "de-DE";
Thread.CurrentThread.CurrentCulture = new CultureInfo(Settings.Default.Culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(Settings.Default.Culture);
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
在我的wpf项目中,我添加了两个资源文件:
Resources\English.resx and Resources\German.resx
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
对于英语,它以这种方式完美地运作.但是,基于本地语言,我如何使用以下内容自动切换到德语:资源:German.LabelHello?