6

私のプログラムのメインメニューは、ContextMenu構成されたMenuItems. プログラムのローカリゼーション中に (リソース ディクショナリを使用して)、 をのそれぞれのDynamicResourceとして設定しました。不思議なことにコンパイルされますが、ローカリゼーション中の変更には影響しないようです (上の言語は変更されません)。HeaderMenuItemsDynamicResourceHeaders

の例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>

MenuItemコントロールの制約は何ですか? で動作するはずDynamicResourceですか?私の全体的な目標は、これらをローカライズするstringsことですが、どうすればよいですか?

このプログラムは WPF です。ありがとうございました。

更新: これは、App.xaml ファイルでリソース ディクショナリが参照される方法です。

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
             <ResourceDictionary Source="Lang.en-US.xaml" />
        </ResourceDictionary.MergedDictionaries>
    <ResourceDictionary>
<Application.Resources>

更新 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>

更新 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();
}
4

1 に答える 1