During WP development, we often encounter problems where images cannot be displayed, videos and music cannot be played, and addresses are correct. What's the reason, according to the msdn study, the build action was improperly set.
Right-click the resource file and select Properties to open the Properties window, for example:
In the build action of the WP resource file, we often use the following situations:
- None: This file will be ignored and will not participate in compilation and output.
- Compile: Files will be compiled into Microsoft intermediate language (IL), such as files with a file extension of CS
- Content: The file will be packaged into the xap file and used as an independent file
- Page: In WP, all XAML page files belong to pages, except app. XAML files.
- Resource: The file will be compiled into the. dll file of the xap file package.
How do we select the build action of the resource file?
Before speaking, we have to talk about how to access the resource file path in the case of content and resource;
- Content: The Path to the resource file is relatively simple, such "/../.."
- Resource: The Path for accessing resource files is cumbersome, such as "/phoneapp1; component/images/back.png", phoneapp1 is the project name, and component is the fixed name.
Image files
As mentioned in the previous section, the layers of ApplicationBar and Silverlight are completely separated in WP, so there are two situations:
The icon file of ApplicationBar should be set to the content method, and the Silverlight level should be set to the resource method.
Multimedia files
For example, for music and video files, these resource files should be set to the content mode.
Why? Microsoft provides the following explanation:
Set build action to content for Media
Media Processing on Windows Phone is optimized to use files and network streams, but not in-memory streams. This means that any media files have been ded in the application, such as sound effects, shocould have theirBuild actionSetContentAnd notResource.
For more information, see performance considerations in applications for Windows Phone.