Reputation: 41
I've started using the WPF Localization Extension to localize my resources for WPF projects. I like the library because it can easily locate resource's out of the XAML-Code.
My project contains some assembly (one by specific view) and I want to use one dictionnary resource by assembly that contain the key specific to the assembly. I have a problem on an assembly where I want to translate a DataGrid.
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn Header="{lex:Loc Test}" Width="Auto"/>
</DataGrid.Columns>
</DataGrid>
In the usercontrol header:
xmlns:lex="http://wpflocalizeextension.codeplex.com"
lex:ResxLocalizationProvider.DefaultAssembly="MyModules.Test"
lex:ResxLocalizationProvider.DefaultDictionary="Resources"
The translation work in design time. But at runtime, I have the key:Test at the header text. After I click on one row of the grid, the translation is correctly updated and it work perfectly but I need to click on a row. In other usercontrol of another assembly, I use a simple TextBlock and the translation work fine directly.
In the main assembly, I initialize the application:
LocalizeDictionary.Instance.SetCurrentThreadCulture = true;
LocalizeDictionary.Instance.SetCultureCommand.Execute("fr");
What I need to do?
Upvotes: 2
Views: 2875
Reputation: 41
Answer from MrCircuit
What you describe is a deeper problem of WPF: The DataGrid breaks the Parent/Child relationship tree that is needed for Attached Property retrieval. Therefore, the loc extensions inside the DataGrid can't access the DefaultAssembly and DefaultDictionary values.
Possible workarounds are: (A) to add these attached properties inside of your DataGrid elements (B) to use the extended key syntax: Assembly:Dictionary:Key The option B that I have tested work fine. Thanks
Upvotes: 2