WPF implements no-refresh dynamic switching multi-language (internationalization)

Source: Internet
Author: User
Tags mscorlib

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.