Always null when loading a resource using the Application.getresourcestream method

Source: Internet
Author: User

We can pre-use the resources, slices, music, etc. in the program into the project, package it into the XAP document, and call from it when needed. Let's talk about the concrete implementation method.

The first step is to save the data in the project.

1, right click on the project name-add-new folder (English version of the translation), the folder name in the image as an example, the need to drag the picture in, of course, you can not build, directly drag the picture to the project record,

2, select the picture just dragged in, Look at the bottom right corner of the Properties tab, if not, right-click the picture, select Properties. Build Action Select Resource.

The second step, the program call.

 System.IO.Stream src = application.getresourcestream (The new Uri ("/ph Oneapp4;component/image/a.png ", urikind.relative)).
      Stream; 

 

Key in the format of the URI, PHONEAPP4 is the project name, component is the fixed path, image/a.jpg is the relative path of the picture resource, gets the stream , in the official Microsoft example, use the following method to convert to a picture:

 BitmapImage bi = new BitmapImage (); Bi.            SetSource (SRC);            Image img = new image (); Img. Source = bi; 
----------------------------------------------------------------------------------------------------------- ------------
The test is always null due to the fact that the Application.getresourcestream method is discovering that the resource is being loaded, right-click Properties-> in the Build action to select Resource, as shown in

And then recompile the run to load the resources.

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.