Windows Store App Globalization: Referencing string resources in XAML elements

Source: Internet
Author: User

in the application, you can use the XAML element and background code refer to the string resource in the resource file in two ways. This section first describes how to refer to the relevant knowledge points of a string resource in a XAML element.

in the XAML element can be used by using the x:uid property to reference a string resource in a resource file, which is stored in a resource file, which describes how to create a new resource file in a project, add a string resource, and XAML element through the x:uid property references a string resource in the resource file.

in Visual Studio Create a new Windows App Store's blank app project and named Stringresourcesinx AML, create a new name in the project named "Strings"In the folder, in the"Stringsfolder, add a sub-folder namedZH-CN, which is used to store resource files in Chinese language. In theZH-CNto add a resource file in a folder, right-click theZH-CNthe folderàAddànew Item, in the Add New Item window, select the resource file(. resw)", namedResources, and then click the Add button. Open this resource file in which to add18-1The two resources shown.

Figure 18-1 in the STRINGS/ZH-CN/RESOURCES.RESW two resources added in the resource file

Once you've done this, you can use x:uid in the control property to reference string resources. In mainpage.xaml file grid element add a textblock control, using x:uid stringresources.text Span style= "font-family:; mso-ascii-font-family: "times New roman" "> Resource, the code is as follows:

<textblock text= "" x:uid= "stringresources" margin= "500,230,660,440" fontsize= "/>

in the above code,x:uidproperty retrieves theSTRINGS/ZH-CN/RESOURCES.RESWresource files, putStringresources.textThe value of the resource "Hello World" assigns toTextBlockcontrol'sTextproperty. In theXAMLThe resource name of the resource referenced in the element is the "resource name.property name as written in the resource file, used when referencing a resourcex:uid= "Resource Name"retrieves the resource, using the corresponding property to receive the resource value. This is why the figure18-1The first resource shown is the. Textend, and inTextBlockcontrol is used in theTextproperty to receive the resource value. In theTextBlockcontrol, delete theTextproperties can also achieve the same effect. Then run the program, the screen will show "Hello World", effect see figure18-3.

can also be in" strings " add a " en-us " folder is used to store resource files in English language. In " en-us "folder to create a newly named" resources.resw "resource file, open the resource file to add 18-2

Figure 18-2 in the STRINGS/EN-US/RESOURCES.RESW two resources added in the resource file

at this time change system language preferences, textblock control text

To change language preferences: Open Control Panel, select" Clock, language, and Region " à "language". Move the language you want to set as your preference to the first place in the language list. If you don't have a language to use in the list, you can click the Add Language button to add those languages to the list of languages and move up to the top of the list.

In this example, the Chinese (Simplified) and English languages are used, if the top of the list of languages is not one of these two, The app runtime displays text information in a language that is supported by the next app in the language list. If there is no English or Chinese (Simplified) in the Language list, the app displays text information in a language that is natively supported by default, written in the project file's defaultlanguage property, the project file is in the same folder as the project, with .csproj Span style= "font-family:; mso-ascii-font-family: "times New roman" "> or .vbproj is the suffix name. You can open the project file by opening Notepad and view and set the defaultlanguage property.

to run the program viewTextBlockcontrol displays text information in two different languages, respectively, to makeChinese (Simplified) and Englishas the language preference. When the language preference is Chinese (Simplified), run the program, the interface will show "Hello World", the effect18-3is shown. When the language preference is English, the program is run and the interface displays "Hello World, the effect18-4is shown.

                     

          Figure18-3The preferred language item is Effects in Chinese (Simplified)         Figure18-4the effect of the preferred language item as English

This section explains how to XAML element is used in the x:uid property refers to a string resource in a resource file, the next section describes how to XAML element To reference the file resource.

Windows Store App Globalization: Referencing string resources in XAML elements

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.