我在本地化方面工作不多,但我可能会使用自定义转换器来解决这个问题。 (当您使用 ComboBox 时,我假设您正在开发 Windows Phone Store 应用程序,而不是 Windows Phone Silverlight 应用程序)。
1:将枚举值的翻译添加到不同的 Resources.resw 文件(例如,/Strings/en-US/Resources.resw 用于美国英语,请参阅 http://code.msdn.microsoft.com/windowsapps/Application-resources-and-cd0c6eaa),表格将如下所示:
|-------------|--------------|--------------|
| Name | Value | Comment |
|-------------|--------------|--------------|
| Cash | Cash | |
| PrepaidCard | Prepaid card | |
| CreditCard | Credit card | |
| Project | Project | |
2:然后创建一个自定义转换器:
public class LocalizationConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return ResourceLoader.GetForCurrentView().GetString(value.ToString());
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
3:将其添加到App.xaml中的资源字典例如:
<Application.Resources>
<local:LocalizationConverter x:Key="LocalizationConverter" />
</Application.Resources>
4:在ComboBox,创建一个使用这个转换器的项目模板:
<ComboBox x:Name="typeComboxBox">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource LocalizationConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
可能有更简单的方法,但这是我目前能想到的最好的方法。