Click here to Skip to main content
15,113,245 members
Articles / Desktop Programming / WPF
Posted 31 Oct 2010


51 bookmarked

Simplest Way to Implement Multilingual WPF Application

Rate me:
Please Sign up or sign in to vote.
4.77/5 (33 votes)
31 Oct 2010CPOL4 min read
Easiest way to handle Localization in your WPF application


Globalization is one of the concepts that comes to mind when we create applications that might run in different geographical locations. Based on the Culture code, we need to modify our application. This is a very common case for many developers. I thought let's discuss what I implemented as the most cunning way to deal with this in your WPF application.

Points of Interest

Globalization is the most common issue to every application. Many of us might have searched over time to find out the easiest way to do a Multilingual Application. Believe me, I did the same thing like you. After doing that, I found a lots of articles on the internet. For instance, you can see one from MSDN:

If you have already read the article, you might have found that there is no such actual implementation that clearly demonstrates the concept. That is why I thought of writing a concrete article for you to easily implement a truly Multilingual Application.

Using the Code


If you have downloaded the sample application, you can see that I have created a login screen, just to show how it works. To try, just run the application you will find a screen just like the one shown above.

Put Username and Password Same, and press login button. You will see the screen below:


Next, go to Control Panel - > Regional & Language Option and change the Language to French(Canada), and Re run the application.


You will find a different screen as below:


And if you put credentials and press "connexion" (Login) button, you will see "Échec de l'authentification" (Authentication Failed).
Now I will discuss how can you implement this type of application yourself.

The Implementation

To start implementing this application, I have added one window. I have also designed the window with some look and feel. You can see them, but this is nothing to deal with our application, so I left out their implementation.

After creating the initial look and feel, which suits me, I added a folder named "Resources" (the name of which can be anything). I added two resource Dictionary to define my resource keys which I will use for my application.


1. Creating the Resource File

The resource files are named as StringResources.xaml,, etc. You can add as many resource files as you want, each of which corresponds to its own Culture.
Inside the resource files, you must declare the ResourceKeys. I have used system:String to define the Resources.

      xmlns ="" 
xmlns: x="" 
xmlns: system="clr-namespace:System;assembly=mscorlib">

<system:String x:Key="close">Close</system:String>
<system:String x:Key="login">Login</system:String>
<!-- All StringResources Goes Here -->

Thus you can see, in addition to adding the ResourceDictionary to the Resources Folder, I have added one namespace which points to mscorlib, and named it as system. I have then added the string references like close, login, etc. which are defined to be replaced in the UI.

Similar to this, I have added another file for fr-CA, and named it as This will hold all the keys that corresponds to the Resourcekeys for a machine set up with French Canadian.

        xmlns ="" 
<system:String x:Key="close">Fermer</system:String>
<system:String x:Key="login">connexion</system:String>

Thus you can see that I kept the same name for the keys to ensure everything works perfectly. If you have used ASP.NET Globalization, this is almost similar to it.

2. Adding a Resource

After you create the Resource file, it's time to add it to the window. To add, I have just implemented a method which you can place in some utility class. For simplicity, I left it in my window. The method looks like:

private void SetLanguageDictionary()
ResourceDictionary dict = new ResourceDictionary();
switch (Thread.CurrentThread.CurrentCulture.ToString())
  case "en-US":
       dict.Source = new Uri("..\\Resources\\StringResources.xaml",  
case "fr-CA":
        dict.Source = new Uri("..\\Resources\\", 
default :
        dict.Source = new Uri("..\\Resources\\StringResources.xaml", 

This is the most simple implementation. I have added the dictionaries directly to the window resources. I have created an object of ResourceDictionary and pointed to the file that is created for resource to its Source property. This will load the external file directly to the object. And finally added to Window.Resources using this.Resources.MergedDirectories.Add(). As you know, after compiling, WPF holds the relative path intact, so it will not create any errors during runtime.

3. Using the Resource

Finally, it's now time to point ResourceKeys to your XAML to ensure it picks up the appropriate key from the ResourceDictionary. Let us add some controls:

<Button      x:Name="btnLogin"
             Content="{DynamicResource login}"
<Button x:Name="btnClose"
        Content="{DynamicResource close}"

You should note that I have always put the Content of the Button using DynamicResource. This is important to define, because we want the content to be replaced with the appropriate key defined to the Resource will be added later.

Hence, your application is ready.

You can download the sample application from here.

Points of Interest

You should note that you must define the key to the resource file before you use as DynamicResource. Otherwise, you will end up displaying nothing in the UI.

This implementation is totally based on UI elements, there is nothing to deal with translation of dynamic UI text. I will discuss about Translation of Language for dynamic User elements later in another article.


Thus, it is really fun to play with WPF, and as Multilingual application is most likely a common issue, I hope this article will help you in the long run. Try the sample application and see the actual implementation.


  • 31st October, 2010: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Abhishek Sur
India India
Did you like his post?

Oh, lets go a bit further to know him better.
Visit his Website : to know more about Abhishek.

Abhishek also authored a book on .NET 4.5 Features and recommends you to read it, you will learn a lot from it.

Basically he is from India, who loves to explore the .NET world. He loves to code and in his leisure you always find him talking about technical stuffs.

Working as a VP product of APPSeCONNECT, an integration platform of future, he does all sort of innovation around the product.

Have any problem? Write to him in his Forum.

You can also mail him directly to

Want a Coder like him for your project?
Drop him a mail to

Visit His Blog

Dotnet Tricks and Tips

Dont forget to vote or share your comments about his Writing

Comments and Discussions

GeneralMy vote of 1 Pin
copa01724-Feb-20 23:27
Membercopa01724-Feb-20 23:27 
GeneralRe: My vote of 1 Pin
pjrobot19882-Sep-20 6:41
Memberpjrobot19882-Sep-20 6:41 
Questionfacing problem Pin
Member 1256813315-Jun-18 1:09
MemberMember 1256813315-Jun-18 1:09 
QuestionHow to implement a dropdown having all language names and select any one of them and app changes. Pin
Ashish Jain(Be Jovial)16-Jun-15 20:42
MemberAshish Jain(Be Jovial)16-Jun-15 20:42 
QuestionUsing resource in code behind Pin
deltonio24-Mar-15 4:03
professionaldeltonio24-Mar-15 4:03 
AnswerRe: Using resource in code behind Pin
pjrobot19882-Sep-20 6:43
Memberpjrobot19882-Sep-20 6:43 
GeneralRe: Using resource in code behind Pin
deltonio22-Sep-20 22:00
professionaldeltonio22-Sep-20 22:00 
QuestionDefault language Pin
Roberto Salemi11-Feb-15 0:45
MemberRoberto Salemi11-Feb-15 0:45 
Questionwarning Pin
ambika1215-Jan-14 19:40
Memberambika1215-Jan-14 19:40 
AnswerRe: warning Pin
pjrobot198817-Sep-19 6:35
Memberpjrobot198817-Sep-19 6:35 
GeneralMy vote of 5 Pin
selvarajpearl13-Feb-13 1:00
Memberselvarajpearl13-Feb-13 1:00 
GeneralMy vote of 5 Pin
Vipin Sahu10-Dec-12 13:18
MemberVipin Sahu10-Dec-12 13:18 
QuestionXMLParseException Pin
esteenbrink7-Nov-12 11:49
Memberesteenbrink7-Nov-12 11:49 
GeneralMy vote of 5 Pin
Chen Noam6-Mar-12 11:57
MemberChen Noam6-Mar-12 11:57 
GeneralMy vote of 5 Pin
Michał Zalewski1-Nov-10 4:14
MemberMichał Zalewski1-Nov-10 4:14 
GeneralRe: My vote of 5 Pin
Abhishek Sur5-Dec-10 9:00
professionalAbhishek Sur5-Dec-10 9:00 
GeneralThere are some other ways too. I wrote about them here in case you want to compare Pin
Sacha Barber1-Nov-10 1:14
mvaSacha Barber1-Nov-10 1:14 
GeneralRe: There are some other ways too. I wrote about them here in case you want to compare Pin
Abhishek Sur4-Dec-10 22:28
professionalAbhishek Sur4-Dec-10 22:28 
GeneralRe: There are some other ways too. I wrote about them here in case you want to compare Pin
Abhishek Sur5-Dec-10 0:03
professionalAbhishek Sur5-Dec-10 0:03 
GeneralActzual Implementation of the MS LocBaml concept Pin
Reinhard Ostermeier31-Oct-10 23:29
MemberReinhard Ostermeier31-Oct-10 23:29 
GeneralRe: Actzual Implementation of the MS LocBaml concept Pin
Abhishek Sur4-Dec-10 22:30
professionalAbhishek Sur4-Dec-10 22:30 
GeneralMy vote of 5 Pin
Kunal Chowdhury «IN»31-Oct-10 17:45
professionalKunal Chowdhury «IN»31-Oct-10 17:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.