The main menu of my program uses ContextMenu , consisting of MenuItems . During the localization of my program (using Resource Dictionaries), I installed DynamicResource as a Header for each of my MenuItems . Strange DynamicResource compiles, but does not seem to affect any changes during localization (the language in Headers does not change).
Example a 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>
What are the limitations of the MenuItem control? Is it supposed to work with DynamicResource ? My common goal is to localize these strings , how to do this?
This program is in WPF. Thanks.
UPDATE: This is how my resource reference words are referenced in my App.xaml file:
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Lang.en-US.xaml" /> </ResourceDictionary.MergedDictionaries> <ResourceDictionary> <Application.Resources>
UPDATE 2: Example string in the English resource dictionary:
<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>
Update 3: An example function for changing the current resource dictionary to Spanish:
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(); }
source share