Getting started with Metro style app development-Example of Object Access in Metro style app

Source: Internet
Author: User

Resource Operations of Metro style app

For the running environment, see the file access operation example of the metro style app. The following describes some resource operations.

You can perform the following operations on resources:

1. define it in the resources. resw file, and obtain it through X: uid.

For example

The usage is corresponding to the uid in X, as shown in figure

 
<Textblock X: uid = "welcomeworld" horizontalalignment = "Left" Height = "41" margin = "66,50, 137 "textwrapping =" Wrap "text =" textblock "verticalalignment =" TOP "width =" "/>

In this way, the text displayed by textblock is Hello world !, The textblock width is 100. You can adjust it by yourself.

2. access the file. For example

 
<Image Source = "images/sample.png" horizontalalignment = "Left" Height = "200" width = "200" stretch = "uniformtofill"/>

3. Use resourceloader. getstring to obtain resources defined by resources. resw. In this example, resourceloadbtn is displayed as Hello sting1.

 
VaR resourceload = new resourceloader (); resourceloadbtn. content = resourceload. getstring ("string1 ");

Note: string1 is saved in the resources. resw file by default. If the resw file name is not resources. resw, perform the following operations, for example:

 
Void anotherresourcebtn_click (Object sender, routedeventargs e) {var resouceload = new resourceloader ("anotherresources"); anotherresourcebtn. content = resouceload. getstring ("anotherstring ");}

Anotherresources is the anotherresources. resw file.

4. obtain the required resources from other projects. Create an appresourceslibrary class library and create a resources. resw file.

The definition in the resources. resw file is as follows:

The following is the call method.

Void appresourcelibrarybtn_click (Object sender, routedeventargs e) {var resourceloader = new resourceloader ("appresourceslibrary/resources"); appresourcelibrarybtn. content = resourceloader. getstring ("string1") + "from" + appresourceslibrary. localizednameslibrary. libraryname ;}

 

The attribute appresourceslibrary. localizednameslibrary. libraryname is defined in the localizednameslibrary class in the appresourceslibrary class library,

This class is defined as follows:

Public static class localizednameslibrary {static resourceloader = NULL; public static string libraryname {get {string name; getlibraryname ("libraryname", out name); Return name ;}} private Static void getlibraryname (string resourcename, out string resourcevalue) {If (resourceloader = NULL) {resourceloader = new resourceloader ("appresourceclasslibrary/resources");} resourcevalue = resourceloader. getstring (resourcename );}}

The definition of this class is the same as the definition for obtaining resources in the same project, which is not described here.

Summary: The above is only the basic knowledge of resource operations. For more information, see the sample of the metro style app. It also includes resource management.

The above is just a bit of learning experience. If you have any comments or suggestions, please submit them! Of course, I am still studying and making progress together! The next article will introduce some animation operations for Metro app styles.

 

 

 

 

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.