Windows Store App Globalization: Referencing file resources in XAML elements

Source: Internet
Author: User

The previous section explains how to XAML element is used in the x:uid property references a string resource in a resource file and displays different run results by changing the language preference. If you turn a string resource into a file resource, you cannot use the x:uid property To reference these file resources. This section takes a picture as a file resource, changing the display result by changing the language preference, referencing a different picture resource in the XAML element. Here's how to add and reference a picture resource.

first create a newWindowsApp Store's blank app project, and namedFileresourcesinxaml. In the project'sAssetsfolder, create a new two folder with a name of "ZH-CN", another named"en -US". In the "ZH-CNfolder, add the namepicture1.jpgthe picture,18-5is shown. In the "en -US, add the namepicture2.jpgthe picture,18-6is shown. When the add is complete,en -USin the folderpicture2.jpgRename picture topicture1.jpg. In this way, two folders are stored with the same name as each otherpicture1.jpgPicture , but the picture content is different.

                         Figure18-5Image picture1 Figure18-6ImagePicture2

and then inMainPage.xamlof the fileGridelement, add aImageControl and aTextBlockcontrol, byImagecontrol'sSourceProperty Reference is namedPicture1the picture,TextBlockcontrol to display the text message "Output is:", as shown in the following code:

<textblock horizontalalignment=" left "   Fontsize= "height=" margin= "482,100,0,0" textwrapping= "Wrap" text= " show result: " verticalalignment= "Top" width= " 154 "/>

<image horizontalalignment= "left" stretch= "None" source= "Assets/picture1.jpg" height= "$" margin= "511,137,0,0" Verticalalignment= "Top" width= "Bayi"/>

In the code above Image control's Source property specifies a relative path that omits the language folder, and the system automatically selects the image file under the correct directory based on the current language preference.

When setting the language preference to Chinese (Simplified), the run program will display the file named" File .doc "pictures, effects 18-7 file.doc " picture. Effect 18-8

              

     Figure18-7The language preference is apply run effect when Chinese (Simplified)    Figure18-8apply run effect when language preference is English

by the figure18-7and Figure18-8as you can see, when you change your language preferences, the picture resources are displayed differently, which enables you to reference different file resources based on your language preference, and the next section explains how to reference string resources in background code.

Windows Store App Globalization: Referencing file 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.