Sunday, April 2, 2017

Multilingual C# WPF Application


There are several ways of implementing a multilingual application out of those,
  • Using Resource Files
  • Using a Database
  • Using the Config File
  • Using a File Full of Strings (Not good)
are few ways of getting the work done. Out of the above listed methods I will show how to create an application using resource files.
You can either use StaticResource or DynamicResource. StaticResource would be fine if you are not going to change the language while application is running. In this article I will be using StaticResource so let's get started.
(IDE - Visual Studio)

Using Code

1. Create a new WPF project using visual studio and then design a simple UI as below. (In this app, Language menu item has 2 sub menus for 2 languages)

Screen Shot 2017-04-02 at 3.19.37 AM

2. Add two new resource files named Resources.en-US.rsex and 

Note.  name of the resource file must match with the format of, Resources.[name of the culture].rsex. You can find cultural information from these two links link1link2

Screen Shot 2017-04-02 at 3.11.10 AM

3. Move the two resource files inside the Properties.

Screen Shot 2017-04-02 at 3.02.42 AM

4. Create item names of these resource files as following,

In default Resources.rsex file will be inside the properties and this should be modified too.
Screen Shot 2017-04-02 at 3.32.07 AM
Screen Shot 2017-04-02 at 3.22.18 AM
Screen Shot 2017-04-02 at 3.26.23 AM
Note. Access Modifier must be set to Public

5. String values for a component can be assigned inside the .xaml file or in the code behind

Method 1 - Inside the .xaml file
You have to do two things. First one is add this namespace
Then you have to assign the relevant text to the component's text field
For Textblock1's text
Text="{x:Static properties:Resources.TxtBlock1}"

For Button's text
Content="{x:Static properties:Resources.TxtButton}"

Method 2 - In code behind


6. Add System.configuration to reference and indicate the following code set in App.xaml

using System.Configuration;
using System.Globalization;
using System.Windows;
namespace MultilingualApplication


  /// <summary>
  /// Interaction logic for App.xaml
  /// </summary>
  public partial class App : Application
    public App()
      // Set up the language culture
      MultilingualApplication.Properties.Resources.Culture = 
                  new CultureInfo(ConfigurationManager.AppSettings["Culture"]);


Last one, you have to add following code snippet inside the configuration tag in the App.config file.

    <add key="Culture" value="en-US" />

Change the Language

Following set of codes help to change the language. Since I have shown using static resources the application must be restarted to have the effects.

private void MenuEnglish_OnClick(object sender, RoutedEventArgs e)

private void MenuSinhala_OnClick(object sender, RoutedEventArgs e)

private void ChangeLanguage(string lang)
  var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  config.AppSettings.Settings["Culture"].Value = lang;



  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru Dot Net Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.