Click here to Skip to main content
14,029,167 members
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 1 Nov 2010
Licenced CPOL

Localization in Silverlight

, 1 Nov 2010
Rate this:
Please Sign up or sign in to vote.
This example will give you knowledge about how to design your site for different cultures.


From this article, you will understand how to select user interface culture according to the user locality in Silverlight. This article is all about localization in Silverlight. You can also download the source code from here.


When the dynamics website came into the picture, their first motto was to provide only the feature for which it was developed. Their target audience was limited and the culture which they preferred was only English or Chinese or Japanese. But it was hard for them to convert a site that was developed in English language to other languages. They had to manually convert each and every field into the respective language.

Why Do We Need to Read this Article?

This article will give you knowledge about how to create a Silverlight application which is independent of user language. The user will be able to see website controls/fields in his/her own language. With main concept, you can also learn how to use Binding in Silverlight and how to use Resource file in any application.

Enough Talk, Let's Start

Open your favorite editor (I prefer VS2010, but you can use any other editor where you can debug and run Silverlight application).

  1. Create a new project:


  2. Select Silverlight Application and write UICultureDemo name of the project.


  3. Create 2 Textblocks and 1 click button on the MainPage.xaml page.


    <!-- Xaml -->
    <TextBlock Margin="96,8,96,2" 
                         Foreground="#FF371818" />
    <TextBlock Margin="96,8" 
    <Button    Height="29" Margin="87,4,96,4" 
                         HorizontalAlignment="Center" />
  4. In App.xaml.cs file, add the following code in Application_Startup method.
    private void Application_Startup(object sender, StartupEventArgs e)
        CultureInfo culture = new CultureInfo("es");
        Thread.CurrentThread.CurrentCulture = culture;
        Thread.CurrentThread.CurrentUICulture = culture;  
        this.RootVisual = new MainPage();

    Include 2 namespaces at the top of header, otherwise it gives you error while building.

    using System.Globalization;
    using System.Threading;
  5. Add 2 resource files, NameFromStrings.resx and files in the UICultureDemo solution.


  6. Open the NameFromStrings.resx file and change the access modifier to public and also enter some values whose culture should vary depending on the UI culture.


  7. Enter same name as key values in but different values.


  8. Unload the UICultureDemo project as show below. (Right Click on UICulture demo and click on Unload Project.)


  9. Edit UICultureDemo.csproj file as shown below:


  10. Add en;es language in SupportedCultures element as shown below:


  11. Save the Changes and Reload Project.


  12. Add the resource namespace and add application resource key in App.xaml file:
    <!-- Xaml -->
    <Application xmlns=""
            <reource:NameFromString x:Key="myResource" />

    Resource namespace is:


    And add resource is:

        <reource:NameFromString x:Key="myResource" />
  13. Bind the Text Property with the respective name in the resource file with binding source myResource like:
    Text="{Binding FirstName, Source={StaticResource myResource}}"


    <TextBlock Margin="96,8,96,2" 
                     Text="{Binding FirstName, Source={StaticResource myResource}}" 
                     Foreground="#FF371818" />
    <TextBlock Margin="96,8" 
                     Text="{Binding LastName,Source={StaticResource myResource}}" 
                     TextWrapping="Wrap" HorizontalAlignment="Center" 
                     FontSize="13.333" />
    <Button    Content="{Binding ClickMe,Source={StaticResource myResource}}" 
                     x:Name="ClickMe" Width="142" 
                     HorizontalAlignment="Center" />
  14. Now Build and Run the project.
  15. To change the Culture, change the CultureInfo parameter in the App.xaml.cs file:
    CultureInfo culture = new CultureInfo("es");
  16. Run the application and you will see the following window (Style would be different):


If you see the above window after changing the culture, that means "All Is Well" or you can download this project code from here.

Next Article

In the next article, I will explain how to use Expression Blend to bind user control and how to use class library to share the same resource file among different projects. Thank you very much for reading this article.


  • 1st November, 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

Durgaprasad Budhwani
Software Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 2 Pin
Ehsan yazdani rad27-Nov-12 21:30
memberEhsan yazdani rad27-Nov-12 21:30 
GeneralRe: My vote of 2 Pin
Durgaprasad Budhwani27-Nov-12 23:22
memberDurgaprasad Budhwani27-Nov-12 23:22 
GeneralRe: My vote of 2 Pin
Ehsan yazdani rad6-May-13 21:42
memberEhsan yazdani rad6-May-13 21:42 
GeneralMy vote of 5 Pin
Pramodmca0926-Jan-11 19:28
memberPramodmca0926-Jan-11 19:28 
GeneralMy vote of 4 Pin
ramonesteban7826-Nov-10 0:26
memberramonesteban7826-Nov-10 0:26 
GeneralRe: My vote of 4 Pin
Durgaprasad Budhwani28-Nov-10 18:51
memberDurgaprasad Budhwani28-Nov-10 18:51 
GeneralGood start Pin
Mamta D9-Nov-10 0:39
memberMamta D9-Nov-10 0:39 
GeneralRe: Good start Pin
Durgaprasad Budhwani9-Nov-10 0:51
memberDurgaprasad Budhwani9-Nov-10 0:51 
GeneralMy vote of 1 Pin
hussain1234566-Nov-10 20:36
memberhussain1234566-Nov-10 20:36 
GeneralRe: My vote of 1 Pin
Kunal Chowdhury «IN»7-Nov-10 21:18
mentorKunal Chowdhury «IN»7-Nov-10 21:18 
GeneralMy vote of 1 Pin
mem54671-Nov-10 8:44
membermem54671-Nov-10 8:44 
GeneralRe: My vote of 1 Pin
Durgaprasad Budhwani1-Nov-10 19:06
memberDurgaprasad Budhwani1-Nov-10 19:06 
GeneralRe: My vote of 1 Pin
Durgaprasad Budhwani1-Nov-10 21:52
memberDurgaprasad Budhwani1-Nov-10 21:52 
GeneralRe: My vote of 1 Pin
hussain1234566-Nov-10 21:26
memberhussain1234566-Nov-10 21:26 
GeneralRe: My vote of 1 Pin
Kunal Chowdhury «IN»7-Nov-10 21:17
mentorKunal Chowdhury «IN»7-Nov-10 21:17 
GeneralRe: My vote of 1 Pin
hussain1234566-Nov-10 21:33
memberhussain1234566-Nov-10 21:33 
GeneralMy vote of 5 Pin
Kunal Chowdhury «IN»1-Nov-10 2:15
mentorKunal Chowdhury «IN»1-Nov-10 2:15 
GeneralRe: My vote of 5 Pin
Durgaprasad Budhwani1-Nov-10 2:17
memberDurgaprasad Budhwani1-Nov-10 2:17 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190419.4 | Last Updated 1 Nov 2010
Article Copyright 2010 by Durgaprasad Budhwani
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid