Switch cultures for WPF application dynamically

2010-07-05


I searched long time for a good solution for dynamically switching cultures for a WPF application. Seems many coders just mentioned the 3rd party component such as WPF Localization Extension. Yes, WPF Localization Extension is a perfect component for us. If you use it, you can get many features about WPF Localization.

My question is: is it possible to use a simple solution ? Yes, I found this article : Simple WPF Localization.

However, I still don't think I have gotten what I wanted. can we just use WPF itself to get our language switching on the fly ?

Finally, I found a wonderful solution guide from this place. I followed this answer, and added some own code, and got my multiple language dynamically switching work.

The following is my steps which I followed the original steps (Please forgive me I have to copy some of original content from above place):

**Step 1) Create a new WPF resource dictionary file under a resource folder (you can have your own resource folder which you created), later you will put all strings which in your application into this resource dictionary.

for example: my resource dictionary file is ResourceFiles/StringResDict.xaml**. ResourceFiles is my own folder.

add the following code into StringResDict.xaml file:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib">

<!-- String resource that can be localized --> <system:String x:Key="File">File</system:String> </ResourceDictionary>

Sorry, I am working now, so I will finish this blog this night.....