1. The use of the. xaml file format for internationalization in WPF
Resource Dictionary (WPF)
2. Create default language files and other language files
Here, in English as the default language, create a new Resource Dictionary (WPF) file, named Defaultlanguage.xaml, with the following contents:
<resourcedictionary xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "http// Schemas.microsoft.com/winfx/2006/xaml " xmlns:sys=" Clr-namespace:system;assembly=mscorlib "><!-- This line is newly added-- <sys:string x:key= "OK" > ok </sys:String> <sys:string x:key= "Cancel" > Cancel </sys:String></ResourceDictionary>
The default language file BuildAction to be set to Page,
For ease of management, it is common to place all language files in one directory, where the lang directory is created,
Then in the creation of another language file, here is the Chinese, named Zh_cn.xaml, the content is as follows:
<resourcedictionary xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "http// Schemas.microsoft.com/winfx/2006/xaml " xmlns:sys=" Clr-namespace:system;assembly=mscorlib "> <sys: String x:key= "OK" > ok </sys:String> <sys:string x:key= "Cancel" > cancel </sys: String></resourcedictionary>
Other non-default languages should have the following settings:
BuildAction is set to: Content; Copytooutputdirectory is set to: Copy if newer ( do it first, cause not clear )
WPF implements no-refresh dynamic switching multi-language (internationalization)