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.