I am working on localizing a GUI in WPF. The code that I post here will be from a prototype because I am trying to make this question as simple as possible.
I am using Resource Dictionaries to set the content of the strings in my window. I have two of them, one is German, and the other is English.
German 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">
<!-- The name of this ResourceDictionary. Should not be localized. -->
<sys:String x:Key="ResourceDictionaryName" Localization.Comments="$Content(DoNotLocalize)">Loc-de-DE</sys:String>
<!--- Button -->
<sys:String x:Key="MainButton_Title">Hallo Welt!</sys:String>
<sys:String x:Key="EnglishButton">Englisch</sys:String>
<sys:String x:Key="GermanButton">Deutsch</sys:String>
</ResourceDictionary>
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">
<!-- The name of this ResourceDictionary. Should not be localized. -->
<sys:String x:Key="ResourceDictionaryName" Localization.Comments="$Content(DoNotLocalize)">Loc-en-US</sys:String>
<!--- Buttons -->
<sys:String x:Key="MainButton_Title">Hello World!</sys:String>
<sys:String x:Key="EnglishButton">English</sys:String>
<sys:String x:Key="GermanButton">German</sys:String>
</ResourceDictionary>
I also have dynamically set the content of my buttons in the XAML window:
<Button Content="{DynamicResource MainButton_Title}" Margin="59,68,0,80" Name="button1" HorizontalAlignment="Left" Width="152" />
<Button Content="{DynamicResource EnglishButton}" Height="23" HorizontalAlignment="Right" Margin="0,83,87,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
<Button Content="{DynamicResource GermanButton}" Height="23" HorizontalAlignment="Right" Margin="0,0,87,90" Name="button3" VerticalAlignment="Bottom" Width="75" />
I want the language to change to English when I click the English button, and change to German when I click the German button. I have gotten this far, but what I don't know is the actual code that would be needed to tell the program to change it's Resource Dictionary. I'm guessing this would go in code-behind under the two button's click events, and might also have some code in the XAML window.
These are the resources that I've used, but I am posting this question because the end solution is not clear enough to me:
-http://www.wpfsharp.com/2012/01/27/how-to-change-language-at-run-time-in-wpf-with-loadable-resource-dictionaries-and-dynamicresource-binding/
-http://msdn.microsoft.com/en-us/library/bb613547.aspx
-http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/03/creating-and-consuming-resource-dictionaries-in-wpf-and-silverlight.aspx
Thank you for your help!