我正在创建一个C#WPF MVVM应用程序,并且正忙于添加不同的语言。 现在我用它包含了很多像行的XAML文件:读取language.xaml文件中的值
<system:String x:Key="btnNew">New</system:String>
<system:String x:Key="btnEdit">Edit</system:String>
程序读取特定的文件夹,得到不同的语言文件(English.xaml,Dutch.xaml)和所选文件添加到在Resources.MergedDictionaties:
void updateLanguage(int id)
{
string sSelectedLanguage = obcLanguages[id].sRealName; // Get selected language name
ResourceDictionary dict = new ResourceDictionary(); // Create new resource dictionary
string sSelectedLanguageUrl = "pack://siteoforigin:,,,/Languages/" + sSelectedLanguage; // Create url to file
dict.Source = new Uri(sSelectedLanguageUrl, UriKind.RelativeOrAbsolute);
App.Current.MainWindow.Resources.MergedDictionaries.Add(dict); // Add new Language file to resources. This file will be automaticly selected
}
我的XAML内容的按钮与DynamicResource
指 'bntNew':
<Button x:Name="btnNewSeam" Content="{DynamicResource btnNew}"Style="{StaticResource BtnStyle}" Command="{Binding newSeamTemplateCommand}" />
这窝ks太棒了。 但现在我使用组合框Observablecollections和我添加选项代码:
obcFunctionsPedalOptions.Add(new clCbbFilltype1("Block", 0));
obcFunctionsPedalOptions.Add(new clCbbFilltype1("Free", 1));
obcFunctionsPedalOptions.Add(new clCbbFilltype1(">0", 2));
但选项“阻止”,“自由”和“> 0”必须与信息翻译来自Language.xaml文件。
我怎样才能读取这个特定的Xml文件的代码,得到一个例子PedalOptions
x:Key并阅读它的选项?
实施例:
<system:String x:Key="PedalOptions">Block, Free, >0</system:String>
这是正确的解决方案。OP需要看看https://msdn.microsoft.com/en-us/library/h6270d0z(v=vs.110).aspx – user9993
嗨克里斯,我基于我的新应用程序:http:// codinginfinity。我/后/ 2015年5月10日/ localization_of_a_wpf_app_the_simple_approach。 一切正常,除了在运行时改变语言。我试过: TranslationSource TranslationSource_temp = new TranslationSource(); TranslationSource_temp.CurrentCulture = CultureInfo.GetCultureInfo(“de-DE”); 但它没有奏效。 请任何帮助 –
@ GerbertvanVeldhuizen - 请提出一个新问题。但是运行时对语言的改变很难。 – ChrisF