我使用了WPF中的资源文件来存放mutil language数据。
resource文件如下:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:String x:Key="AllNews">
所有
</sys:String>
<sys:String x:Key="China">
中国
</sys:String>
<sys:String x:Key="World">
世界
</sys:String>
<sys:String x:Key="News">
新闻
</sys:String>
<sys:String x:Key="Other">
其他
</sys:String>
</ResourceDictionary>
<Button Height="23" Name="btnChina" Width="75" Click="Button_Click" Content="{DynamicResource China}">
(string)Application.Current.Resources.MergedDictionaries[0][key]查阅了相关书籍,终于找到了解决的方案,使用UIElement对象的SetResourceReference方法来实现{DynamicResource XXXX}的功能:
item = new MenuItem();
item.SetResourceReference(MenuItem.HeaderProperty, key);
this.menuMain.Items.Add(item);问题解决,睡觉!