Windows Phone 7 (WP7) Development reads local resource files

Source: Internet
Author: User

In the development process, we often need to use many resource files, such as the city name and Pinyin ing list.

Why should these files be used as local resource files? This is generally because:

1. We do not like to hard code these resources into code, such as a city list "Beijing-Beijing, Shanghai-Shanghai ,......", If it is hard-coded into the code, it is obviously not as flexible as getting XML (or JSON, or even TXT files.

2. Although such resources can be obtained from the network, it is better to perform frequent operations locally (and then load them to the memory ), in addition, such resources are not very large.

 

WP7 is easy to read local resource files. For example, we have a city. xml file to read:

First, copy the file to our project, and then set its properties {copy to the output directory: Always copy, generate operation: Resource} (of course, it can also be set to copy data if it is newer. I personally feel that there is no difference in the use effect)

Then, the Code calls:

Streamresourceinfo reader = application. getresourcestream (New uri ("/{your project name}; component/{file path}", urikind. Relative ));

Xelement xml = xelement. Load (reader. Stream );

It may also be because I am not using JSON much. I personally feel that XML in WP7 is easier to use than JSON. This is not the focus of this Article. If you do not know about XML parsing, you can refer to relevant materials.

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.