multilingual wpf application

前端 未结 4 2033
野的像风
野的像风 2020-12-23 10:50

I have a WPF application (in English) and I would like to let users to select different languages. I have read some possibilities to change languages in runtime applications

4条回答
  •  甜味超标
    2020-12-23 11:37

    You can follow these steps:

    1. Creating the resource files

      Add this file StringResources.xaml to Resources directory. Here is an example:

      
      
           Close
      
      

      You can create several files, one for each language.

    2. Adding the resource (Call this when you start your application)

      private void SetLanguageDictionary()
      {
           ResourceDictionary dict = new ResourceDictionary();
           switch (Thread.CurrentThread.CurrentCulture.ToString())
           { 
             case "en-US":
               dict.Source = new Uri("..\\Resources\\StringResources.xaml", UriKind.Relative);
               break;
             case "fr-CA":
               dict.Source = new Uri("..\\Resources\\StringResources.fr-CA.xaml", UriKind.Relative);
               break;
             default :
               dict.Source = new Uri("..\\Resources\\StringResources.xaml",UriKind.Relative);
               break;
           }
           this.Resources.MergedDictionaries.Add(dict);
      }
      
    3. Using the Resource, like this -

    Source: https://www.codeproject.com/Articles/123460/Simplest-Way-to-Implement-Multilingual-WPF-Applica

提交回复
热议问题