Why don't MenuItems functions work with DynamicResource?

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(); } 
+6
source share
1 answer

Have you added the LANGUAGE.xaml file to App.ResourceDictionary or are you using ResourceDictionary?

eg.

 <Application.Resources> <ResourceDictionary Source="LANGUAGE1.xaml" /> <ResourceDictionary Source="LANGUAGE2.xaml" /> </Application.Resources> 

Should you not link to your resource dictionaries?

Update:

If you change

 <MenuItem Header="{DynamicResource open}" /> 

to

 <MenuItem Header="{StaticResource open}" /> 

Will this work? Or even does

 <TextBox DockPanel.Dock="Top" Text="{StaticResource open}" /> 

work?

It seems your xaml should work, which makes me wonder if you configured the localization in your application correctly?

How to configure localization in .net 4.5 see this msdn link

+2
source

All Articles