为什么MenuItems不能与DynamicResource一起使用?

Eri*_*ark 6 c# xaml localization menuitem dynamicresource

我的程序的主菜单采用的是ContextMenu组成MenuItems.在我的程序(使用资源字典)的定位,我设置DynamicResourceHeader我的每一个MenuItems.奇怪的DynamicResource编译,但似乎并没有影响本地化过程中的任何变化(语言上Headers没有变化).

例子MenuItem:

//I'm not sure if the x:Name or the PlacementRectangle is interfering with anything...
<ContextMenu x:Name="MainContextMenu" PlacementRectangle="{Binding RelativeSource={RelativeSource Self}}">
<MenuItem Header="{DynamicResource open}" />
</ContextMenu>
Run Code Online (Sandbox Code Playgroud)

MenuItem控制的限制是什么?它应该合作DynamicResource吗?我的总体目标是本地化这些strings,我该怎么做?

该程序在WPF中.谢谢.

更新: 这是我的App.xaml文件中引用我的资源字典的方式:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
             <ResourceDictionary Source="Lang.en-US.xaml" />
        </ResourceDictionary.MergedDictionaries>
    <ResourceDictionary>
<Application.Resources>
Run Code Online (Sandbox Code Playgroud)

更新2: 我的英语资源字典中的示例字符串:

<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="open">Open</sys:String>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

更新3: 我如何将当前资源字典更改为西班牙语的示例函数:

private void spanishChange_Click(object sender, RoutedEventArgs e)
{
    Application.Current.Resources.MergedDictionaries.Clear();

    Application.Current.Resources.MergedDictionaries.Add(
            (ResourceDictionary)Application.LoadComponent(new Uri("LangspES.xaml", UriKind.Relative)));

    LanguageChange.FireLanguageChanged();
}
Run Code Online (Sandbox Code Playgroud)

Pau*_*hra 2

您是否已将 LANGUAGE.xaml 文件添加到 App.ResourceDictionary 或控件 ResourceDictionary 中?

例如

<Application.Resources>
    <ResourceDictionary Source="LANGUAGE1.xaml" />
    <ResourceDictionary Source="LANGUAGE2.xaml" />
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

如果不是,你如何引用你的资源字典?

更新:

如果你改变

<MenuItem Header="{DynamicResource open}" />
Run Code Online (Sandbox Code Playgroud)

<MenuItem Header="{StaticResource open}" />
Run Code Online (Sandbox Code Playgroud)

那么它有效吗?或者甚至是

<TextBox DockPanel.Dock="Top" Text="{StaticResource open}" />
Run Code Online (Sandbox Code Playgroud)

工作 ?

看起来你的 xaml 应该可以工作,这让我想知道你是否在你的应用程序中正确设置了本地化?

有关如何在 .net 4.5 中设置本地化的信息,请参阅此 msdn 链接