How to start an internationalized WPF-Project in SharpDevelop 4.2?

前端 未结 1 1773
青春惊慌失措
青春惊慌失措 2021-01-03 06:34

I want to create a Software, where the User can choose between several Languages.

As a start i want to learn how to handle Internationalization, since i have never

1条回答
  •  粉色の甜心
    2021-01-03 07:30

    If you created two ResourceDictionary files you can binding by DynamicResource.

    Example:

    First resource file (Lang.en-US.xaml):

    
    
        Username:
        Password:
        Close
        Login        
    
    

    Second resource file (Lang.pl-PL.xaml):

    
    
        Login:
        Hasło:
        Zamknij
        Zaloguj
    
    

    Set default language in Application resources:

     
            
                
                    
                
            
     
    

    Let's say that we have ComboBox like below:

    
                    
                    
      
    

    Code-behind SelectionChanged:

     private void cbLang_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
            {
                ResourceDictionary dict = new ResourceDictionary();
    
                switch (((sender as ComboBox).SelectedItem as ComboBoxItem).Tag.ToString())
                {
                    case "en-US":
                        dict.Source = new Uri("Lang.en-US.xaml", UriKind.Relative);
                        break;
                    case "pl-PL":
                        dict.Source = new Uri("Lang.pl-PL.xaml", UriKind.Relative);
                        break;
                    default:
                        break;
                }
                this.Resources.MergedDictionaries.Add(dict);
            }
    

    And you can binding like this:

     
    

    0 讨论(0)
提交回复
热议问题